home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / lang / lisp / clisp-li.000 / clisp-li / clisp-1996-07-22 / src / init.lsp < prev    next >
Encoding:
Text File  |  1996-06-30  |  82.4 KB  |  2,098 lines

  1. ;;;;   INITIALISIERUNGS-FILE
  2.  
  3. (in-package "LISP")
  4.  
  5. (shadow 'system::debug (find-package "SYSTEM"))
  6.  
  7. ;;; Exportierungen:
  8. (export '(
  9. ;; Typen:
  10. array atom bignum bit bit-vector character common compiled-function
  11. complex cons double-float fixnum float function hash-table integer keyword
  12. list #+LOGICAL-PATHNAMES logical-pathname long-float nil null number package
  13. pathname random-state ratio rational readtable real sequence short-float
  14. simple-array simple-bit-vector simple-string simple-vector single-float
  15. standard-char stream file-stream synonym-stream broadcast-stream
  16. concatenated-stream two-way-stream echo-stream string-stream string
  17. string-char symbol t vector satisfies values mod signed-byte unsigned-byte
  18. ;; Konstanten:
  19. lambda-list-keywords lambda-parameters-limit nil t call-arguments-limit
  20. multiple-values-limit pi boole-clr boole-set boole-1 boole-2 boole-c1 boole-c2
  21. boole-and boole-ior boole-xor boole-eqv boole-nand boole-nor boole-andc1
  22. boole-andc2 boole-orc1 boole-orc2 most-positive-fixnum most-negative-fixnum
  23. most-positive-short-float least-positive-short-float least-negative-short-float
  24. most-negative-short-float most-positive-single-float
  25. least-positive-single-float least-negative-single-float
  26. most-negative-single-float most-positive-double-float
  27. least-positive-double-float least-negative-double-float
  28. most-negative-double-float most-positive-long-float least-positive-long-float
  29. least-negative-long-float most-negative-long-float
  30. least-positive-normalized-short-float least-negative-normalized-short-float
  31. least-positive-normalized-single-float least-negative-normalized-single-float
  32. least-positive-normalized-double-float least-negative-normalized-double-float
  33. least-positive-normalized-long-float least-negative-normalized-long-float
  34. short-float-epsilon single-float-epsilon double-float-epsilon
  35. long-float-epsilon short-float-negative-epsilon single-float-negative-epsilon
  36. double-float-negative-epsilon long-float-negative-epsilon
  37. char-code-limit char-font-limit char-bits-limit char-control-bit char-meta-bit
  38. char-super-bit char-hyper-bit array-rank-limit array-dimension-limit
  39. array-total-size-limit internal-time-units-per-second
  40. ;; Variablen:
  41. *macroexpand-hook* *gensym-counter* *package* *modules* *random-state*
  42. *evalhook* *applyhook* + ++ +++ - * ** *** / // /// *standard-input*
  43. *standard-output* *error-output* *query-io* *debug-io* *terminal-io*
  44. *trace-output* *read-base* *read-suppress* *readtable* *print-readably*
  45. *print-escape* *print-pretty* *print-circle* *print-base* *print-radix*
  46. *print-case* *print-gensym* *print-level* *print-length* *print-array*
  47. *read-default-float-format* *default-pathname-defaults* *load-paths*
  48. *load-verbose* *load-print* *load-echo* *load-pathname* *load-truename*
  49. *break-on-warnings* *compile-warnings* *compile-verbose* *compile-print*
  50. *compile-file-pathname* *compile-file-truename* *features*
  51. ;; Funktionen:
  52. coerce type-of upgraded-array-element-type typep subtypep null symbolp
  53. atom consp listp numberp integerp rationalp floatp realp complexp characterp
  54. stringp bit-vector-p vectorp simple-vector-p simple-string-p
  55. simple-bit-vector-p arrayp packagep functionp compiled-function-p commonp eq
  56. eql equal equalp not symbol-value symbol-function fdefinition boundp fboundp
  57. special-form-p set makunbound fmakunbound get-setf-method
  58. get-setf-method-multiple-value apply funcall mapcar maplist mapc mapl mapcan
  59. mapcon values values-list macro-function macroexpand macroexpand-1 proclaim
  60. get remprop symbol-plist getf get-properties symbol-name make-symbol
  61. copy-symbol gensym gentemp symbol-package keywordp make-package in-package
  62. find-package package-name package-nicknames rename-package package-use-list
  63. package-used-by-list package-shadowing-symbols list-all-packages delete-package
  64. intern find-symbol unintern export unexport import shadowing-import shadow
  65. use-package unuse-package find-all-symbols provide require zerop plusp minusp
  66. oddp evenp = /= < > <= >= max min + - * / 1+ 1- conjugate gcd lcm exp expt
  67. log sqrt isqrt abs phase signum sin cos tan cis asin acos atan sinh cosh tanh
  68. asinh acosh atanh float rational rationalize numerator denominator floor
  69. ceiling truncate round mod rem ffloor fceiling ftruncate fround decode-float
  70. scale-float float-radix float-sign float-digits float-precision
  71. integer-decode-float complex realpart imagpart logior logxor logand logeqv
  72. lognand lognor logandc1 logandc2 logorc1 logorc2 boole lognot logtest logbitp
  73. ash logcount integer-length byte byte-size byte-position ldb ldb-test mask-field
  74. dpb deposit-field random make-random-state random-state-p standard-char-p
  75. graphic-char-p string-char-p alpha-char-p upper-case-p lower-case-p
  76. both-case-p digit-char-p alphanumericp char= char/= char< char> char<= char>=
  77. char-equal char-not-equal char-lessp char-greaterp char-not-greaterp
  78. char-not-lessp char-code char-bits char-font code-char make-char character
  79. char-upcase char-downcase digit-char char-int int-char char-name name-char
  80. char-bit set-char-bit complement constantly elt subseq copy-seq length reverse
  81. nreverse make-sequence concatenate map map-into some every notany notevery
  82. reduce fill replace remove remove-if remove-if-not delete delete-if
  83. delete-if-not remove-duplicates delete-duplicates substitute substitute-if
  84. substitute-if-not nsubstitute nsubstitute-if nsubstitute-if-not find find-if
  85. find-if-not position position-if position-if-not count count-if count-if-not
  86. mismatch search sort stable-sort merge car cdr caar cadr cdar cddr caaar
  87. caadr cadar caddr cdaar cdadr cddar cdddr caaaar caaadr caadar caaddr cadaar
  88. cadadr caddar cadddr cdaaar cdaadr cdadar cdaddr cddaar cddadr cdddar cddddr
  89. cons tree-equal endp list-length nth first second third fourth fifth sixth
  90. seventh eighth ninth tenth rest nthcdr last list list* make-list append
  91. copy-list copy-alist copy-tree revappend nconc nreconc butlast nbutlast ldiff
  92. rplaca rplacd subst subst-if subst-if-not nsubst nsubst-if nsubst-if-not sublis
  93. nsublis member member-if member-if-not tailp adjoin union nunion intersection
  94. nintersection set-difference nset-difference set-exclusive-or
  95. nset-exclusive-or subsetp acons pairlis assoc assoc-if assoc-if-not rassoc
  96. rassoc-if rassoc-if-not make-hash-table hash-table-p gethash remhash maphash
  97. clrhash hash-table-count hash-table-rehash-size hash-table-rehash-threshold
  98. hash-table-size hash-table-test sxhash make-array vector aref svref
  99. array-element-type array-rank array-dimension array-dimensions array-total-size
  100. array-in-bounds-p array-row-major-index row-major-aref adjustable-array-p
  101. bit sbit bit-and bit-ior bit-xor bit-eqv bit-nand bit-nor bit-andc1 bit-andc2
  102. bit-orc1 bit-orc2 bit-not array-has-fill-pointer-p fill-pointer vector-push
  103. vector-push-extend vector-pop adjust-array char schar string= string-equal
  104. string< string> string<= string>= string/= string-lessp string-greaterp
  105. string-not-greaterp string-not-lessp string-not-equal make-string string-trim
  106. string-left-trim string-right-trim string-upcase string-downcase
  107. string-capitalize nstring-upcase nstring-downcase nstring-capitalize string
  108. eval evalhook applyhook constantp make-synonym-stream make-broadcast-stream
  109. make-concatenated-stream make-two-way-stream make-echo-stream
  110. make-string-input-stream make-string-output-stream get-output-stream-string
  111. streamp open-stream-p input-stream-p output-stream-p stream-element-type close
  112. broadcast-stream-streams concatenated-stream-streams echo-stream-input-stream
  113. echo-stream-output-stream synonym-stream-symbol two-way-stream-input-stream
  114. two-way-stream-output-stream interactive-stream-p
  115. copy-readtable readtablep set-syntax-from-char set-macro-character
  116. get-macro-character make-dispatch-macro-character
  117. set-dispatch-macro-character get-dispatch-macro-character readtable-case
  118. read read-preserving-whitespace read-delimited-list read-line read-char
  119. unread-char peek-char listen read-char-no-hang clear-input read-from-string
  120. parse-integer read-byte write prin1 print pprint princ write-to-string
  121. prin1-to-string princ-to-string write-char write-string write-line terpri
  122. fresh-line finish-output force-output clear-output write-byte format y-or-n-p
  123. yes-or-no-p wild-pathname-p pathname-match-p translate-pathname
  124. #+LOGICAL-PATHNAMES logical-pathname
  125. #+LOGICAL-PATHNAMES translate-logical-pathname
  126. #+LOGICAL-PATHNAMES logical-pathname-translations
  127. #+LOGICAL-PATHNAMES load-logical-pathname-translations
  128. compile-file-pathname pathname truename parse-namestring merge-pathnames
  129. make-pathname pathnamep pathname-host pathname-device pathname-directory
  130. pathname-name pathname-type pathname-version namestring file-namestring
  131. directory-namestring host-namestring enough-namestring user-homedir-pathname
  132. open rename-file delete-file probe-file file-write-date file-author
  133. file-position file-length load directory error cerror warn break compile
  134. compile-file disassemble
  135. documentation  variable structure type ; drei Dokumentations-Typen
  136. describe inspect room ed dribble apropos apropos-list get-decoded-time
  137. get-universal-time decode-universal-time encode-universal-time
  138. get-internal-run-time get-internal-real-time sleep lisp-implementation-type
  139. lisp-implementation-version machine-type machine-version machine-instance
  140. software-type software-version short-site-name long-site-name identity
  141. ;; Special-forms:
  142. eval-when quote function setq progn let let* locally compiler-let progv flet
  143. labels macrolet symbol-macrolet if block return-from tagbody go
  144. multiple-value-call multiple-value-prog1 catch unwind-protect throw declare
  145. the load-time-value
  146. ;; Macros:
  147. deftype defun defvar defparameter defconstant and or psetq setf psetf shiftf
  148. rotatef define-modify-macro defsetf define-setf-method prog1 prog2
  149. when unless cond
  150. case typecase  otherwise ; otherwise als Marker fⁿr die catchall-clause
  151. return loop do do* dolist dotimes prog prog* multiple-value-list
  152. multiple-value-bind multiple-value-setq defmacro remf do-symbols
  153. do-external-symbols do-all-symbols incf decf push pushnew pop defstruct
  154. with-open-stream with-input-from-string with-output-to-string
  155. with-standard-io-syntax with-open-file
  156. check-type assert etypecase ctypecase ecase ccase trace untrace step time
  157. formatter
  158. english deutsch francais
  159. ;; sonstige Markierer:
  160. eval load compile ; EVAL-WHEN-Situationen
  161. special type ftype function inline notinline ignore ignorable optimize speed
  162. space safety compilation-speed debug declaration dynamic-extent compile ; DECLARE-Specifier
  163. interpreter compiler ; Features
  164. ))
  165.  
  166. (sys::%proclaim-constant 'lambda-list-keywords
  167.   '(&optional &rest &key &allow-other-keys &aux &body &whole &environment)
  168. )
  169. (export lambda-list-keywords)
  170.  
  171. (sys::%putd 'exit #'sys::%exit)
  172. (sys::%putd 'quit #'sys::%exit)
  173. (sys::%putd 'bye #'sys::%exit)
  174. (export '(exit quit bye))
  175.  
  176. (export 'the-environment)
  177.  
  178. (proclaim '(special *features*))
  179. (import *features*)
  180. (export *features*)
  181.  
  182. (in-package "SYSTEM" :nicknames '("SYS" "COMPILER") :use '("LISP"))
  183. (proclaim '(special compiler::*compiling*))
  184. (setq compiler::*compiling* nil)
  185.  
  186. (in-package "CLOS" :use '("LISP"))
  187. ;;; Exportierungen:
  188. (export '(
  189.   ;; Namen von Funktionen und Macros:
  190.   slot-value slot-boundp slot-makunbound slot-exists-p with-slots with-accessors
  191.   find-class class-of defclass defmethod call-next-method next-method-p
  192.   defgeneric generic-function generic-flet generic-labels
  193.   class-name
  194.   no-applicable-method no-primary-method no-next-method
  195.   find-method add-method remove-method
  196.   compute-applicable-methods method-qualifiers function-keywords
  197.   slot-missing slot-unbound
  198.   print-object describe-object
  199.   make-instance initialize-instance reinitialize-instance shared-initialize
  200.   ;; Namen von Klassen:
  201.   standard-class structure-class built-in-class
  202.   standard-object standard-generic-function standard-method
  203.   ;; andere Symbole:
  204.   standard ; Methoden-Kombination
  205. ))
  206.  
  207. (in-package "LISP")
  208. ; Exportierungen von conditio.lsp
  209. (export '(
  210.   handler-bind                  ; vorgezogen fⁿr compiler.lsp
  211.   find-restart compute-restarts ; vorgezogen fⁿr user1.lsp
  212.   invoke-restart-interactively  ; dito
  213.   restart                       ; vermeide Konflikt mit user1.lsp
  214.   continue                      ; vermeide Konflikt mit user1.lsp
  215.   end-of-file                   ; vermeide Konflikt mit init.lsp, user2.lsp
  216.   ; Typen fⁿr error-of-type:
  217.   condition warning serious-condition error storage-condition type-error
  218.   program-error control-error package-error print-not-readable stream-error
  219.   end-of-file file-error cell-error unbound-variable undefined-function
  220.   arithmetic-error division-by-zero floating-point-overflow
  221.   floating-point-underflow
  222. ))
  223.  
  224. (in-package "USER" :use '("LISP" "CLOS"))
  225.  
  226. ; Optionale Files wie macros3.lsp, defs2.lsp, loop.lsp, defs3.lsp machen ihre
  227. ; Exportierungen selber.
  228.  
  229.  
  230. (in-package "SYSTEM")
  231.  
  232. #-COMPILER ; nur beim Bootstrappen
  233. (progn
  234.  
  235. ; vorlΣufig soll bei GET_CLOSURE nicht expandiert werden:
  236. (sys::%putd '%expand-lambdabody-main
  237.   (function %expand-lambdabody-main
  238.     (lambda (lambdabody venv fenv)
  239.       (declare (source nil) (ignore venv fenv))
  240.       lambdabody
  241. ) ) )
  242.  
  243. ; vorlΣufig soll defun ganz trivial expandiert werden:
  244. (sys::%putd 'defun
  245.   (cons 'sys::macro
  246.     (function defun
  247.       (lambda (form env)
  248.         (declare (ignore env))
  249.         #|
  250.         (let ((name (cadr form))
  251.               (lambdalist (caddr form))
  252.               (body (cdddr form)))
  253.           `(SYS::%PUTD ',name (FUNCTION ,name (LAMBDA ,lambdalist ,@body)))
  254.         )
  255.         |#
  256.         (let ((name (cadr form)))
  257.           (list 'sys::%putd (list 'quote name)
  258.             (list 'function name (cons 'lambda (cddr form)))
  259.         ) )
  260.     ) )
  261. ) )
  262.  
  263. )
  264.  
  265. (let ((h (cons 'sys::macro
  266.            (function
  267.              (lambda (form env)
  268.                (declare (ignore env))
  269.                (apply #'(lambda (&key &allow-other-keys)) form)
  270.                (list 'SYS::LANGUAGE
  271.                      (getf form 'ENGLISH)
  272.                      (getf form 'DEUTSCH)
  273.                      (getf form 'FRANCAIS)
  274.       )) ) ) ) )
  275.   (sys::%putd 'ENGLISH h)
  276.   (sys::%putd 'DEUTSCH h)
  277.   (sys::%putd 'FRANCAIS h)
  278. )
  279.  
  280. (sys::%putd 'sys::exported-lisp-symbol-p
  281.   (function sys::exported-lisp-symbol-p
  282.     (lambda (symbol)
  283.       (let ((string (symbol-name symbol)))
  284.         (or (let ((p (find-package "LISP")))
  285.               (and p
  286.                 (multiple-value-bind (s f) (find-symbol string p)
  287.                   (and (eq s symbol) (eq f ':external))
  288.             ) ) )
  289.             (let ((p (find-package "COMMON-LISP")))
  290.               (and p
  291.                 (multiple-value-bind (s f) (find-symbol string p)
  292.                   (and (eq s symbol) (eq f ':external))
  293.     ) ) )   ) ) )
  294. ) )
  295.  
  296. (sys::%putd 'sys::remove-old-definitions
  297.   (function sys::remove-old-definitions
  298.     (lambda (symbol) ; entfernt die alten Funktionsdefinitionen eines Symbols
  299.       (if (special-form-p symbol)
  300.         (error-of-type 'error
  301.           (DEUTSCH "~S ist eine Special-Form und darf nicht umdefiniert werden."
  302.            ENGLISH "~S is a special form and may not be redefined."
  303.            FRANCAIS "~S est une forme spΘciale et ne peut pas Ωtre redΘfinie.")
  304.           symbol
  305.       ) )
  306.       (if (and (or (fboundp symbol) (macro-function symbol))
  307.                (sys::exported-lisp-symbol-p symbol)
  308.           )
  309.         (cerror (DEUTSCH "Die alte Definition wird weggeworfen."
  310.                  ENGLISH "The old definition will be lost"
  311.                  FRANCAIS "L'ancienne dΘfinition sera perdue.")
  312.                 (DEUTSCH "D~2@*~:[ie~;er~]~0@* COMMON-LISP-~A ~S wird umdefiniert."
  313.                  ENGLISH "Redefining the COMMON LISP ~A ~S"
  314.                  FRANCAIS "L~2@*~:[a~;e~]~0@* ~A ~S de COMMON-LISP va Ωtre redΘfini~:[e~;~].")
  315.                 (fbound-string symbol) ; "Funktion" bzw. "Macro"
  316.                 symbol
  317.                 (macro-function symbol)
  318.       ) )
  319.       (fmakunbound symbol) ; Funktions-/Macro-Definition streichen
  320.       ; Property sys::definition wird nicht entfernt, da sie sowieso
  321.       ; bald neu gesetzt wird.
  322.       (remprop symbol 'sys::macro) ; Macro-Definition streichen
  323.       (when (get symbol 'sys::documentation-strings) ; Dokumentation streichen
  324.         (sys::%set-documentation symbol 'FUNCTION nil)
  325.       )
  326.       (when (get symbol 'sys::inline-expansion)
  327.         (sys::%put symbol 'sys::inline-expansion t)
  328.       )
  329.       (when (get symbol 'sys::traced-definition) ; Trace streichen
  330.         (warn (DEUTSCH "DEFUN/DEFMACRO: ~S war getraced und wird umdefiniert!"
  331.                ENGLISH "DEFUN/DEFMACRO: redefining ~S; it was traced!"
  332.                FRANCAIS "DEFUN/DEFMACRO : ~S Θtait tracΘe et est redΘfinie!")
  333.               symbol
  334.         )
  335.         (untrace2 symbol)
  336.     ) )
  337. ) )
  338.  
  339. ; THE-ENVIRONMENT wie in SCHEME
  340. (sys::%putd '%the-environment
  341.   (function %the-environment
  342.     (lambda (form env)
  343.       (declare (ignore form))
  344.       (sys::svstore env 0 (svref (svref env 0) 2)) ; *evalhook*-Bindung streichen
  345.       env
  346.     )
  347. ) )
  348. (sys::%putd '%the-environment-error
  349.   (function %the-environment-error
  350.     (lambda ()
  351.       (error-of-type 'program-error
  352.         (DEUTSCH "~S ist in compiliertem Code unm÷glich."
  353.          ENGLISH "~S is impossible in compiled code"
  354.          FRANCAIS "~S est impossible dans du code compilΘ.")
  355.         'the-environment
  356.     ) )
  357. ) )
  358. (sys::%putd 'the-environment
  359.   (cons 'sys::macro
  360.     (function the-environment
  361.       (lambda (form env)
  362.         (declare (ignore form env))
  363.         '(progn
  364.            (eval-when ((not eval)) (%the-environment-error))
  365.            (let ((*evalhook* #'%the-environment)) 0)
  366.          )
  367. ) ) ) )
  368.  
  369. ; liefert den Namen des impliziten Blocks zu einem Funktionsnamen
  370. (defun block-name (funname)
  371.   (if (atom funname) funname (second funname))
  372. )
  373.  
  374. ;;; Funktionen zum Expandieren von Macros innerhalb eines Codestⁿckes
  375. ;;;
  376. ;;; Insgesamt wird der gesamte Code (einer Funktion) durchgegangen und
  377. ;;; globale und lokale Macros expandiert.
  378. ;;; Aus       #'(lambda lambdalist . body)
  379. ;;; wird so   #'(lambda expanded-lambdalist
  380. ;;;               (declare (source (lambdalist . body))) . expanded-body
  381. ;;;             )
  382. ;;; Durch diese Deklaration ist gewΣhrleistet, da▀ eine bereits einmal
  383. ;;; durchlaufene Funktion als solche erkannt und nicht unn÷tigerweise ein
  384. ;;; zweites Mal durchlaufen wird.
  385.  
  386. ; Vorsicht! Fⁿrs Bootstrappen (erkennbar an #-COMPILER) mⁿssen manche der
  387. ; Funktionen in primitiverem Lisp (ohne do, do*, case) geschrieben werden.
  388.  
  389. (PROGN
  390.  
  391. (proclaim '(special *keyword-package*))
  392. (setq *keyword-package* (find-package "KEYWORD"))
  393.  
  394. (proclaim '(special *fenv*))
  395. ; *fenv* = Das aktuelle Function-Environment wΣhrend der Expansion
  396. ; einer Form. Struktur: NIL oder ein 2n+1-elementiger Vektor
  397. ; (n1 f1 ... nn fn next), wo die ni Funktionsnamen sind, die fi ihre funktionale
  398. ; Bedeutung sind (Closure oder (MACRO . Closure) oder noch NIL); bei next
  399. ; geht's ebenso weiter.
  400.  
  401. ; (fenv-assoc s fenv) sucht Symbol s in Function-Environment fenv.
  402. (defun fenv-assoc (s fenv)
  403.   (if fenv
  404.     (if (simple-vector-p fenv)
  405.       #+COMPILER
  406.       (do ((l (1- (length fenv)))
  407.            (i 0 (+ i 2)))
  408.           ((= i l) (fenv-assoc s (svref fenv i)))
  409.         (if (equal s (svref fenv i))
  410.           (return (svref fenv (1+ i)))
  411.       ) )
  412.       #-COMPILER
  413.       (let ((l (1- (length fenv)))
  414.             (i 0))
  415.         (block nil
  416.           (tagbody
  417.             1 (if (= i l) (return-from nil (fenv-assoc s (svref fenv i))))
  418.               (if (equal s (svref fenv i))
  419.                 (return-from nil (svref fenv (1+ i)))
  420.               )
  421.               (setq i (+ i 2))
  422.               (go 1)
  423.       ) ) )
  424.       (error-of-type 'type-error
  425.         :datum fenv :expected-type '(or null simple-vector)
  426.         (DEUTSCH "~S ist kein korrektes Function-Environment."
  427.          ENGLISH "~S is an invalid function environment"
  428.          FRANCAIS "~S n'est pas un environnement de fonctions correct.")
  429.         fenv
  430.     ) )
  431.     'T ; nicht gefunden
  432. ) )
  433. ; Stellt fest, ob ein Funktionsname im Function-Environment fenv nicht
  434. ; definiert ist und daher auf die globale Funktion verweist.
  435. (defun global-in-fenv-p (s fenv) ; vorlΣufig
  436.   (eq (fenv-assoc s fenv) 'T)
  437. )
  438.  
  439. (proclaim '(special *venv*))
  440. ; *venv* = Das aktuelle Variablen-Environment wΣhrend der Expansion
  441. ; einer Form. Struktur: NIL oder ein 2n+1-elementiger Vektor
  442. ; (n1 v1 ... nn vn next), wo die ni Symbole sind, die vi ihre
  443. ; syntaktische Bedeutung (Symbol-Macro-Objekt oder sonstiges); bei next
  444. ; geht's ebenso weiter.
  445.  
  446. ; (venv-assoc s venv) sucht Symbol s in Variablen-Environment venv.
  447. ; Liefert den Wert (oder NIL falls kein Wert).
  448. ; Vorsicht: Der Wert kann #<SPECDECL> oder #<SYMBOL-MACRO ...> sein, darf
  449. ; daher in interpretiertem Code nicht in einer Variablen zwischengespeichert
  450. ; werden.
  451. (defun venv-assoc (s venv)
  452.   (if venv
  453.     (if (simple-vector-p venv)
  454.       #+COMPILER
  455.       (do ((l (1- (length venv)))
  456.            (i 0 (+ i 2)))
  457.           ((= i l) (venv-assoc s (svref venv i)))
  458.         (if (eq s (svref venv i))
  459.           (return (svref venv (1+ i)))
  460.       ) )
  461.       #-COMPILER
  462.       (let ((l (1- (length venv)))
  463.             (i 0))
  464.         (block nil
  465.           (tagbody
  466.             1 (if (= i l) (return-from nil (venv-assoc s (svref venv i))))
  467.               (if (eq s (svref venv i))
  468.                 (return-from nil (svref venv (1+ i)))
  469.               )
  470.               (setq i (+ i 2))
  471.               (go 1)
  472.       ) ) )
  473.       (error-of-type 'type-error
  474.         :datum venv :expected-type '(or null simple-vector)
  475.         (DEUTSCH "~S ist kein korrektes Variablen-Environment."
  476.          ENGLISH "~S is an invalid variable environment"
  477.          FRANCAIS "~S n'est pas un environnement de variables correct.")
  478.         venv
  479.     ) )
  480.     (and (boundp s) (%symbol-value s)) ; nicht gefunden
  481. ) )
  482.  
  483. ; Die meisten Expansionsfunktionen liefern zwei Werte: Das Expansions-
  484. ; ergebnis, der zweite Wert (NIL oder T) zeigt an, ob darin etwas verΣndert
  485. ; wurde.
  486.  
  487. ; (%expand-cons ...) setzt ein cons zusammen. 2 Werte.
  488. ; form=alte Form,
  489. ; expf,flagf = Expansion des First-Teils,
  490. ; expr,flagr = Expansion des Rest-Teils.
  491. (defun %expand-cons (form expf flagf expr flagr)
  492.   (if (or flagf flagr)
  493.     (values (cons expf expr) t)
  494.     (values form nil)
  495. ) )
  496.  
  497. #+COMPILER
  498.  
  499. ; (%expand-form form) expandiert eine ganze Form. 2 Werte.
  500. (defun %expand-form (form)
  501.   (if (atom form)
  502.     (let (h)
  503.       (if (and (symbolp form) (symbol-macro-p (setq h (venv-assoc form *venv*))))
  504.         (values (sys::%record-ref h 0) t)
  505.         (values form nil)
  506.     ) )
  507.     ; form ist CONS
  508.     (let ((f (first form)))
  509.       (if (function-name-p f)
  510.         (let ((h (fenv-assoc f *fenv*)))
  511.           ; f ist in *fenv* assoziiert zu h
  512.           (if (eq h 'T)
  513.             ; f hat keine lokale Definition
  514.             ; Nun die einzelnen Expander fⁿr die Special-forms:
  515.             (case f
  516.               ((RETURN-FROM THE)
  517.                 ; 1. Argument lassen, alle weiteren expandieren
  518.                 (multiple-value-call #'%expand-cons form
  519.                   (first form) nil
  520.                   (multiple-value-call #'%expand-cons (rest form)
  521.                     (second form) nil
  522.                     (%expand-list (cddr form))
  523.               ) ) )
  524.               ((QUOTE GO DECLARE LOAD-TIME-VALUE) ; nichts expandieren
  525.                 (values form nil)
  526.               )
  527.               (FUNCTION
  528.                 ; Falls erstes bzw. zweites Argument Liste,
  529.                 ; als Lambda-Ausdruck expandieren.
  530.                 (multiple-value-call #'%expand-cons form
  531.                   'FUNCTION nil
  532.                   (if (atom (cddr form))
  533.                     (if (function-name-p (second form))
  534.                       (let ((h (fenv-assoc (second form) *fenv*)))
  535.                         (cond ((or (eq h 'T) (closurep h) (null h)) (values (rest form) nil))
  536.                               ((and (consp h) (eq (first h) 'MACRO))
  537.                                (error-of-type 'program-error
  538.                                  (DEUTSCH "~S: ~S unzulΣssig, da ~S ein lokaler Macro ist"
  539.                                   ENGLISH "~S: ~S is illegal since ~S is a local macro"
  540.                                   FRANCAIS "~S : ~S est illΘgal car ~S est un macro local")
  541.                                  '%expand form (second form)
  542.                               ))
  543.                               (t (error-of-type 'error
  544.                                    (DEUTSCH "~S: Falscher Aufbau eines Function-Environment: ~S"
  545.                                     ENGLISH "~S: invalid function environment ~S"
  546.                                     FRANCAIS "~S : mauvais environnement de fonction ~S")
  547.                                    '%expand *fenv*
  548.                               )  )
  549.                       ) )
  550.                       (if (atom (second form))
  551.                         (error-of-type 'program-error
  552.                           (DEUTSCH "~S: ~S unzulΣssig, da ~S kein Symbol"
  553.                            ENGLISH "~S: ~S is invalid since ~S is not a symbol"
  554.                            FRANCAIS "~S : ~S est illΘgal car ~S n'est pas un symbole")
  555.                           '%expand form (second form)
  556.                         )
  557.                         (multiple-value-call #'%expand-cons (rest form)
  558.                           (%expand-lambda (second form))
  559.                           (cddr form) nil
  560.                     ) ) )
  561.                     (multiple-value-call #'%expand-cons (rest form)
  562.                       (second form) nil
  563.                       (multiple-value-call #'%expand-cons (cddr form)
  564.                         (%expand-lambda (third form))
  565.                         (cdddr form) nil
  566.               ) ) ) ) )
  567.               (EVAL-WHEN
  568.                 ; Falls die Situation COMPILE angegeben ist, fⁿhre den Body
  569.                 ; als PROGN aus, gib eine Form zurⁿck, die ohne Seiteneffekte
  570.                 ; dieselben Werte liefert.
  571.                 ; Sonst expandiere alle Argumente ab dem zweiten als Formen.
  572.                 (if (member 'COMPILE (second form))
  573.                   (values
  574.                     (list 'values-list
  575.                       (list 'quote
  576.                         (multiple-value-list (eval (cons 'PROGN (cddr form))))
  577.                     ) )
  578.                     t
  579.                   )
  580.                   (multiple-value-call #'%expand-cons form
  581.                     (first form) nil
  582.                     (multiple-value-call #'%expand-cons (rest form)
  583.                       (second form) nil
  584.                       (%expand-list (cddr form))
  585.               ) ) ) )
  586.               (LET ; Variablenliste und Body expandieren
  587.                 (let ((*venv* *venv*))
  588.                   (%expand-special-declarations (cddr form))
  589.                   (multiple-value-call #'%expand-cons form
  590.                     (first form) nil
  591.                     (multiple-value-call #'%expand-cons (rest form)
  592.                       (%expand-varspez (second form))
  593.                       (%expand-list (cddr form))
  594.               ) ) ) )
  595.               (LET* ; Variablenliste und Body expandieren
  596.                 (let ((*venv* *venv*))
  597.                   (%expand-special-declarations (cddr form))
  598.                   (multiple-value-call #'%expand-cons form
  599.                     (first form) nil
  600.                     (multiple-value-call #'%expand-cons (rest form)
  601.                       (%expand-varspez* (second form))
  602.                       (%expand-list (cddr form))
  603.               ) ) ) )
  604.               (LOCALLY ; Body expandieren
  605.                 (let ((*venv* *venv*))
  606.                   (%expand-special-declarations (cdr form))
  607.                   (multiple-value-call #'%expand-cons form
  608.                     (first form) nil
  609.                     (%expand-list (cdr form))
  610.               ) ) )
  611.               (MULTIPLE-VALUE-BIND ; Form und Body getrennt expandieren
  612.                 (let ((*venv* *venv*))
  613.                   (%expand-special-declarations (cdddr form))
  614.                   (multiple-value-call #'%expand-cons form
  615.                     'MULTIPLE-VALUE-BIND nil
  616.                     (multiple-value-call #'%expand-cons (rest form)
  617.                       (second form) nil
  618.                       (multiple-value-call #'%expand-cons (cddr form)
  619.                         (%expand-form (third form))
  620.                         (progn
  621.                           (%expand-lexical-variables (second form))
  622.                           (%expand-list (cdddr form))
  623.               ) ) ) ) ) )
  624.               (COMPILER-LET
  625.                 ; Variablenliste im leeren Environment und Body expandieren
  626.                 (progv
  627.                   (mapcar #'%expand-varspec-var (second form))
  628.                   (mapcar #'%expand-varspec-val (second form))
  629.                   (values (%expand-form (cons 'PROGN (cddr form))) t)
  630.               ) )
  631.               (COND ; Alle Teilformen der Klauseln expandieren:
  632.                 (multiple-value-call #'%expand-cons form
  633.                   (first form) nil
  634.                   (%expand-cond (rest form))
  635.               ) )
  636.               (BLOCK
  637.                 ; Body expandieren. Falls darin ein RETURN-FROM auf diesen
  638.                 ; Block vorkommt, behalte BLOCK. Sonst mache ein PROGN daraus.
  639.                 (multiple-value-bind (body flagb) (%expand-list (cddr form))
  640.                   (if (%return-p (second form) body)
  641.                     (multiple-value-call #'%expand-cons form
  642.                       (first form) nil
  643.                       (multiple-value-call #'%expand-cons (rest form)
  644.                         (second form) nil
  645.                         body flagb
  646.                     ) )
  647.                     (values
  648.                       (cond ((atom body) body)
  649.                             ((null (cdr body)) (car body))
  650.                             (t (cons 'progn body))
  651.                       )
  652.                       t
  653.               ) ) ) )
  654.               ((SETQ PSETQ) ; jedes zweite Argument expandieren
  655.                 (if (%expand-setqlist-macrop (rest form))
  656.                   (let ((new (if (eq (first form) 'SETQ) 'SETF 'PSETF)))
  657.                     (values
  658.                       (%expand-form
  659.                         (funcall (macro-function new) (cons new (rest form)) (vector *venv* *fenv*))
  660.                       )
  661.                       t
  662.                   ) )
  663.                   (multiple-value-call #'%expand-cons form
  664.                     (first form) nil
  665.                     (%expand-setqlist (rest form))
  666.               ) ) )
  667.               (MULTIPLE-VALUE-SETQ ; 1. Argument lassen, alle weiteren expandieren
  668.                 (if (%expand-varlist-macrop (second form))
  669.                   (values (%expand-form (cons 'MULTIPLE-VALUE-SETF (rest form))) t)
  670.                   (multiple-value-call #'%expand-cons form
  671.                     'MULTIPLE-VALUE-SETQ nil
  672.                     (multiple-value-call #'%expand-cons (rest form)
  673.                       (second form) nil
  674.                       (%expand-list (cddr form))
  675.               ) ) ) )
  676.               (TAGBODY
  677.                 ; alle Argumente expandieren, dabei entstehende Atome weglassen
  678.                 (multiple-value-call #'%expand-cons form
  679.                   (first form) nil
  680.                   (%expand-tagbody (rest form))
  681.               ) )
  682.               (PROGN ; alle Argumente expandieren, evtl. vereinfachen.
  683.                 (if (null (rest form))
  684.                   (values nil t)
  685.                   (if (null (cddr form))
  686.                     (values (%expand-form (second form)) t)
  687.                     (multiple-value-call #'%expand-cons form
  688.                       (first form) nil
  689.                       (%expand-list (rest form))
  690.               ) ) ) )
  691.               (FLET ; Funktionsdefinitionen expandieren,
  692.                     ; Body im erweiterten Environment expandieren
  693.                 (if (null (second form))
  694.                   (values (%expand-form (cons 'PROGN (cddr form))) t)
  695.                   (let ((newfenv (%expand-fundefs-1 (second form))))
  696.                     (multiple-value-call #'%expand-cons form
  697.                       (first form) nil
  698.                       (multiple-value-call #'%expand-cons (rest form)
  699.                         (%expand-fundefs-2 (second form))
  700.                         (let ((*fenv* (apply #'vector newfenv)))
  701.                           (%expand-list (cddr form))
  702.               ) ) ) ) ) )
  703.               (LABELS ; Funktionsdefinitionen und Body im erweiterten Environment expandieren
  704.                 (if (null (second form))
  705.                   (values (%expand-form (cons 'PROGN (cddr form))) t)
  706.                   (let ((newfenv (%expand-fundefs-1 (second form))))
  707.                     (let ((*fenv* (apply #'vector newfenv)))
  708.                       (multiple-value-call #'%expand-cons form
  709.                         (first form) nil
  710.                         (multiple-value-call #'%expand-cons (rest form)
  711.                           (%expand-fundefs-2 (second form))
  712.                           (%expand-list (cddr form))
  713.               ) ) ) ) ) )
  714.               (MACROLET ; Body im erweiterten Environment expandieren
  715.                 (do ((L1 (second form) (cdr L1))
  716.                      (L2 nil))
  717.                     ((atom L1)
  718.                      (if L1
  719.                        (error-of-type 'program-error
  720.                          (DEUTSCH "Dotted list im Code von MACROLET, endet mit ~S"
  721.                           ENGLISH "code after MACROLET contains a dotted list, ending with ~S"
  722.                           FRANCAIS "Le code de MACROLET contient une paire pointΘe, terminΘe par ~S")
  723.                          L1
  724.                        )
  725.                        (let ((*fenv* (apply #'vector (nreverse (cons *fenv* L2)))))
  726.                          (values (%expand-form (cons 'PROGN (cddr form))) t)
  727.                     )) )
  728.                   (let ((macrodef (car L1)))
  729.                     (if (and (consp macrodef)
  730.                              (symbolp (car macrodef))
  731.                              (consp (cdr macrodef))
  732.                         )
  733.                       (setq L2
  734.                         (cons (make-macro-expandercons macrodef)
  735.                               (cons (car macrodef) L2)
  736.                       ) )
  737.                       (error-of-type 'program-error
  738.                         (DEUTSCH "Falsche Syntax in MACROLET: ~S"
  739.                          ENGLISH "illegal syntax in MACROLET: ~S"
  740.                          FRANCAIS "syntaxe illΘgale dans MACROLET : ~S")
  741.                         macrodef
  742.               ) ) ) ) )
  743.               (SYMBOL-MACROLET ; Body im erweiterten Environment expandieren
  744.                 (do ((L1 (second form) (cdr L1))
  745.                      (L2 nil))
  746.                     ((atom L1)
  747.                      (if L1
  748.                        (error-of-type 'program-error
  749.                          (DEUTSCH "Dotted list im Code von SYMBOL-MACROLET, endet mit ~S"
  750.                           ENGLISH "code after SYMBOL-MACROLET contains a dotted list, ending with ~S"
  751.                           FRANCAIS "Le code de SYMBOL-MACROLET contient une paire pointΘe, terminΘe par ~S")
  752.                          L1
  753.                        )
  754.                        (let ((*venv* (apply #'vector (nreverse (cons *venv* L2)))))
  755.                          (values (%expand-form (cons 'LOCALLY (cddr form))) t)
  756.                     )) )
  757.                   (let ((symdef (car L1)))
  758.                     (if (and (consp symdef)
  759.                              (symbolp (car symdef))
  760.                              (consp (cdr symdef))
  761.                              (null (cddr symdef))
  762.                         )
  763.                       (setq L2
  764.                         (cons (make-symbol-macro (cadr symdef)) (cons (car symdef) L2))
  765.                       )
  766.                       (error-of-type 'program-error
  767.                         (DEUTSCH "Falsche Syntax in SYMBOL-MACROLET: ~S"
  768.                          ENGLISH "illegal syntax in SYMBOL-MACROLET: ~S"
  769.                          FRANCAIS "syntaxe illΘgale dans SYMBOL-MACROLET : ~S")
  770.                         symdef
  771.               ) ) ) ) )
  772.               (%HANDLER-BIND ; Handlerliste und Body expandieren
  773.                 (multiple-value-call #'%expand-cons form
  774.                   (first form) nil
  775.                   (multiple-value-call #'%expand-cons (rest form)
  776.                     (%expand-handlers (second form))
  777.                     (%expand-list (cddr form))
  778.               ) ) )
  779.               (t
  780.                 (cond ((and (symbolp f) (special-form-p f))
  781.                        ; sonstige Special-forms,
  782.                        ; z.B. IF, CATCH, THROW, PROGV, UNWIND-PROTECT, PROGN,
  783.                        ; PROG1, PROG2, WHEN, UNLESS, MULTIPLE-VALUE-LIST,
  784.                        ; MULTIPLE-VALUE-CALL, MULTIPLE-VALUE-PROG1, AND, OR:
  785.                        (multiple-value-call #'%expand-cons form
  786.                          f nil
  787.                          (%expand-list (rest form))
  788.                       ))
  789.                       ((and (symbolp f) (setq h (macro-function f))) ; globale Macro-Definition
  790.                        (values (%expand-form (funcall h form (vector *venv* *fenv*))) t)
  791.                       )
  792.                       (t ; normaler Funktionsaufruf
  793.                        (multiple-value-call #'%expand-cons form
  794.                          f nil
  795.                          (%expand-list (rest form))
  796.             ) ) )     ))
  797.             ; f hat eine lokale Definition
  798.             (cond ((or (closurep h) (null h)); aufzurufende Funktion
  799.                    (multiple-value-call #'%expand-cons form
  800.                      f nil
  801.                      (%expand-list (rest form))
  802.                   ))
  803.                   ((and (consp h) (eq (car h) 'MACRO)) ; zu expandierender Macro
  804.                    (values (%expand-form (funcall (cdr h) form *fenv*)) t)
  805.                   ) ; Expander aufrufen
  806.                   (t (error-of-type 'error
  807.                        (DEUTSCH "Falscher Aufbau eines Function-Environment in ~S: ~S"
  808.                         ENGLISH "bad function environment occurred in ~S: ~S"
  809.                         FRANCAIS "mauvais environnement de fonction dans ~S : ~S")
  810.                        '%expand-form *fenv*
  811.         ) ) )     )  )
  812.         (if (consp f)
  813.           (multiple-value-call #'%expand-cons form
  814.             (%expand-lambda f)
  815.             (%expand-list (rest form))
  816.           )
  817.           (error-of-type 'program-error
  818.             (DEUTSCH "~S: ~S ist keine korrekte Form"
  819.              ENGLISH "~S: invalid form ~S"
  820.              FRANCAIS "~S : forme Lisp incorrecte ~S")
  821.             '%expand-form form
  822. ) ) ) ) ) )
  823.  
  824. #-COMPILER
  825. (progn
  826.  
  827. ; (%expand-form form) expandiert eine ganze Form. 2 Werte.
  828. (defun %expand-form (form)
  829.   (if (atom form)
  830.     (if (and (symbolp form) (symbol-macro-p (venv-assoc form *venv*)))
  831.       (values (sys::%record-ref (venv-assoc form *venv*) 0) t)
  832.       (values form nil)
  833.     )
  834.     ; form ist CONS
  835.     (let ((f (first form)))
  836.       (if (function-name-p f)
  837.         (let ((h (fenv-assoc f *fenv*)))
  838.           ; f ist in *fenv* assoziiert zu h
  839.           (if (eq h 'T)
  840.             ; f hat keine lokale Definition
  841.             (cond ((setq h (get '%expand f)) ; special forms u.Σ.
  842.                    (funcall h form)
  843.                   )
  844.                   ((and (symbolp f) (special-form-p f))
  845.                    ; sonstige Special-forms,
  846.                    ; z.B. IF, CATCH, THROW, PROGV, UNWIND-PROTECT, PROGN,
  847.                    ; PROG1, PROG2, WHEN, UNLESS, MULTIPLE-VALUE-LIST,
  848.                    ; MULTIPLE-VALUE-CALL, MULTIPLE-VALUE-PROG1, AND, OR:
  849.                    (multiple-value-call #'%expand-cons form
  850.                      f nil
  851.                      (%expand-list (rest form))
  852.                   ))
  853.                   ((and (symbolp f) (setq h (macro-function f))) ; globale Macro-Definition
  854.                    (values (%expand-form (funcall h form (vector *venv* *fenv*))) t)
  855.                   )
  856.                   (t ; normaler Funktionsaufruf
  857.                    (multiple-value-call #'%expand-cons form
  858.                      f nil
  859.                      (%expand-list (rest form))
  860.             )     ))
  861.             ; f hat eine lokale Definition
  862.             (cond ((or (closurep h) (null h)); aufzurufende Funktion
  863.                    (multiple-value-call #'%expand-cons form
  864.                      f nil
  865.                      (%expand-list (rest form))
  866.                   ))
  867.                   ((and (consp h) (eq (car h) 'MACRO)) ; zu expandierender Macro
  868.                    (values (%expand-form (funcall (cdr h) form *fenv*)) t)
  869.                   ) ; Expander aufrufen
  870.                   (t (error-of-type 'error
  871.                        (DEUTSCH "Falscher Aufbau eines Function-Environment in ~S: ~S"
  872.                         ENGLISH "bad function environment occurred in ~S: ~S"
  873.                         FRANCAIS "mauvais environnement de fonction dans ~S : ~S")
  874.                        '%expand-form *fenv*
  875.         ) ) )     )  )
  876.         (if (consp f)
  877.           (multiple-value-call #'%expand-cons form
  878.             (%expand-lambda f)
  879.             (%expand-list (rest form))
  880.           )
  881.           (error-of-type 'program-error
  882.             (DEUTSCH "~S: ~S ist keine korrekte Form"
  883.              ENGLISH "~S: invalid form ~S"
  884.              FRANCAIS "~S : forme Lisp incorrecte ~S")
  885.             '%expand-form form
  886. ) ) ) ) ) )
  887.  
  888. ; Nun die einzelnen Expander fⁿr die Special-forms:
  889.  
  890. ; RETURN-FROM, THE:
  891. ; 1. Argument lassen, alle weiteren expandieren
  892. (defun %expand-ab2 (form)
  893.   (multiple-value-call #'%expand-cons form
  894.       (first form) nil
  895.       (multiple-value-call #'%expand-cons (rest form)
  896.           (second form) nil
  897.           (%expand-list (cddr form))
  898. ) )   )
  899. (%put '%expand 'RETURN-FROM #'%expand-ab2)
  900. (%put '%expand 'THE #'%expand-ab2)
  901.  
  902. ; QUOTE, GO, DECLARE, LOAD-TIME-VALUE: nichts expandieren
  903. (let ((fun
  904.         (function %expand-quote/go/declare (lambda (form) (values form nil)))
  905.      ))
  906.   (%put '%expand 'QUOTE fun)
  907.   (%put '%expand 'GO fun)
  908.   (%put '%expand 'DECLARE fun)
  909.   (%put '%expand 'LOAD-TIME-VALUE fun)
  910. )
  911.  
  912. ; FUNCTION:
  913. ; Falls erstes bzw. zweites Argument Liste, als Lambda-Ausdruck expandieren.
  914. (%put '%expand 'FUNCTION
  915.   (function %expand-function
  916.     (lambda (form)
  917.       (multiple-value-call #'%expand-cons form
  918.           'FUNCTION nil
  919.           (if (atom (cddr form))
  920.             (if (function-name-p (second form))
  921.               (let ((h (fenv-assoc (second form) *fenv*)))
  922.                 (cond ((or (eq h 'T) (closurep h) (null h)) (values (rest form) nil))
  923.                       ((and (consp h) (eq (first h) 'MACRO))
  924.                        (error-of-type 'program-error
  925.                          (DEUTSCH "~S: ~S unzulΣssig, da ~S ein lokaler Macro ist"
  926.                           ENGLISH "~S: ~S is illegal since ~S is a local macro"
  927.                           FRANCAIS "~S : n'est pas permis car ~S est un macro local")
  928.                          '%expand form (second form)
  929.                       ))
  930.                       (t (error-of-type 'error
  931.                            (DEUTSCH "~S: Falscher Aufbau eines Function-Environment: ~S"
  932.                             ENGLISH "~S: invalid function environment ~S"
  933.                             FRANCAIS "~S : mauvais environnement de fonction ~S")
  934.                            '%expand *fenv*
  935.                       )  )
  936.               ) )
  937.               (if (atom (second form))
  938.                 (error-of-type 'program-error
  939.                   (DEUTSCH "~S: ~S unzulΣssig, da ~S kein Symbol"
  940.                    ENGLISH "~S: ~S is invalid since ~S is not a symbol"
  941.                    FRANCAIS "~S : ~S est inadmissible car ~S n'est pas un symbole")
  942.                   '%expand form (second form)
  943.                 )
  944.                 (multiple-value-call #'%expand-cons (rest form)
  945.                     (%expand-lambda (second form))
  946.                     (cddr form) nil
  947.             ) ) )
  948.             (multiple-value-call #'%expand-cons (rest form)
  949.                 (second form) nil
  950.                 (multiple-value-call #'%expand-cons (cddr form)
  951.                     (%expand-lambda (third form))
  952.                     (cdddr form) nil
  953.   ) ) )   ) )   )
  954. )
  955.  
  956. ; EVAL-WHEN:
  957. ; Falls die Situation COMPILE angegeben ist, fⁿhre den Body als PROGN aus,
  958. ;   gib eine Form zurⁿck, die ohne Seiteneffekte dieselben Werte liefert.
  959. ; Sonst expandiere alle Argumente ab dem zweiten als Formen.
  960. (%put '%expand 'EVAL-WHEN
  961.   (function %expand-eval-when
  962.     (lambda (form)
  963.       (if (member 'COMPILE (second form))
  964.         (values
  965.           (list 'values-list
  966.             (list 'quote
  967.               (multiple-value-list (eval (cons 'PROGN (cddr form))))
  968.           ) )
  969.           t
  970.         )
  971.         (%expand-ab2 form)
  972.   ) ) )
  973. )
  974.  
  975. ; LET: Variablenliste und Body expandieren
  976. (%put '%expand 'LET
  977.   (function %expand-let
  978.     (lambda (form)
  979.       (let ((*venv* *venv*))
  980.         (%expand-special-declarations (cddr form))
  981.         (multiple-value-call #'%expand-cons form
  982.           (first form) nil
  983.           (multiple-value-call #'%expand-cons (rest form)
  984.             (%expand-varspez (second form))
  985.             (%expand-list (cddr form))
  986.   ) ) ) ) )
  987. )
  988.  
  989. ; LET*: Variablenliste und Body expandieren
  990. (%put '%expand 'LET*
  991.   (function %expand-let*
  992.     (lambda (form)
  993.       (let ((*venv* *venv*))
  994.         (%expand-special-declarations (cddr form))
  995.         (multiple-value-call #'%expand-cons form
  996.           (first form) nil
  997.           (multiple-value-call #'%expand-cons (rest form)
  998.             (%expand-varspez* (second form))
  999.             (%expand-list (cddr form))
  1000.   ) ) ) ) )
  1001. )
  1002.  
  1003. ; LOCALLY: Body expandieren
  1004. (%put '%expand 'LOCALLY
  1005.   (function %expand-locally
  1006.     (lambda (form)
  1007.       (let ((*venv* *venv*))
  1008.         (%expand-special-declarations (cdr form))
  1009.         (multiple-value-call #'%expand-cons form
  1010.           (first form) nil
  1011.           (%expand-list (cdr form))
  1012.   ) ) ) )
  1013. )
  1014.  
  1015. ; MULTIPLE-VALUE-BIND: Form und Body getrennt expandieren
  1016. (%put '%expand 'MULTIPLE-VALUE-BIND
  1017.   (function %expand-multiple-value-bind
  1018.     (lambda (form)
  1019.       (let ((*venv* *venv*))
  1020.         (%expand-special-declarations (cdddr form))
  1021.         (multiple-value-call #'%expand-cons form
  1022.           'MULTIPLE-VALUE-BIND nil
  1023.           (multiple-value-call #'%expand-cons (rest form)
  1024.             (second form) nil
  1025.             (multiple-value-call #'%expand-cons (cddr form)
  1026.               (%expand-form (third form))
  1027.               (progn
  1028.                 (%expand-lexical-variables (second form))
  1029.                 (%expand-list (cdddr form))
  1030.   ) ) ) ) ) ) )
  1031. )
  1032.  
  1033. ; COMPILER-LET: Variablenliste im leeren Environment und Body expandieren
  1034. (%put '%expand 'COMPILER-LET
  1035.   (function %expand-compiler-let
  1036.     (lambda (form)
  1037.       (progv
  1038.         (mapcar #'%expand-varspec-var (second form))
  1039.         (mapcar #'%expand-varspec-val (second form))
  1040.         (values (%expand-form (cons 'PROGN (cddr form))) t)
  1041.   ) ) )
  1042. )
  1043.  
  1044. ; COND: Alle Teilformen der Klauseln expandieren:
  1045. (%put '%expand 'cond
  1046.   (function %expand-cond
  1047.     (lambda (form)
  1048.       (multiple-value-call #'%expand-cons form
  1049.           (first form) nil
  1050.           (%expand-cond (rest form))
  1051.   ) ) )
  1052. )
  1053.  
  1054. ; BLOCK: Body expandieren. Falls darin ein RETURN-FROM auf diesen Block
  1055. ; vorkommt, behalte BLOCK. Sonst mache ein PROGN daraus.
  1056. (%put '%expand 'block
  1057.   (function %expand-block
  1058.     (lambda (form)
  1059.       (multiple-value-bind (body flagb) (%expand-list (cddr form))
  1060.         (if (%return-p (second form) body)
  1061.           (multiple-value-call #'%expand-cons form
  1062.               (first form) nil
  1063.               (multiple-value-call #'%expand-cons (rest form)
  1064.                   (second form) nil
  1065.                   body flagb
  1066.           )   )
  1067.           (values
  1068.             (cond ((atom body) body)
  1069.                   ((null (cdr body)) (car body))
  1070.                   (t (cons 'progn body))
  1071.             )
  1072.             t
  1073.   ) ) ) ) )
  1074. )
  1075.  
  1076. ; SETQ, PSETQ: jedes zweite Argument expandieren
  1077. (let ((fun
  1078.         (function %expand-setq/psetq
  1079.           (lambda (form)
  1080.             (if (%expand-setqlist-macrop (rest form))
  1081.               (let ((new (if (eq (first form) 'SETQ) 'SETF 'PSETF)))
  1082.                 (values
  1083.                   (%expand-form
  1084.                     (funcall (macro-function new) (cons new (rest form)) (vector *venv* *fenv*))
  1085.                   )
  1086.                   t
  1087.               ) )
  1088.               (multiple-value-call #'%expand-cons form
  1089.                 (first form) nil
  1090.                 (%expand-setqlist (rest form))
  1091.         ) ) ) )
  1092.      ))
  1093.   (%put '%expand 'SETQ fun)
  1094.   (%put '%expand 'PSETQ fun)
  1095. )
  1096.  
  1097. ; MULTIPLE-VALUE-SETQ : 1. Argument lassen, alle weiteren expandieren
  1098. (%put '%expand 'multiple-value-setq
  1099.   (function %expand-multiple-value-setq
  1100.     (lambda (form)
  1101.       (if (%expand-varlist-macrop (second form))
  1102.         (values (%expand-form (cons 'MULTIPLE-VALUE-SETF (rest form))) t)
  1103.         (%expand-ab2 form)
  1104.   ) ) )
  1105. )
  1106.  
  1107. ; TAGBODY: alle Argumente expandieren, dabei entstehende Atome weglassen
  1108. (%put '%expand 'tagbody
  1109.   (function %expand-tagbody
  1110.     (lambda (form)
  1111.       (multiple-value-call #'%expand-cons form
  1112.           (first form) nil
  1113.           (%expand-tagbody (rest form))
  1114.   ) ) )
  1115. )
  1116.  
  1117. ; PROGN: alle Argumente expandieren, evtl. vereinfachen.
  1118. (%put '%expand 'progn
  1119.   (function %expand-progn
  1120.     (lambda (form)
  1121.       (if (null (rest form))
  1122.         (values nil t)
  1123.         (if (null (cddr form))
  1124.           (values (%expand-form (second form)) t)
  1125.           (multiple-value-call #'%expand-cons form
  1126.               (first form) nil
  1127.               (%expand-list (rest form))
  1128.   ) ) ) ) )
  1129. )
  1130.  
  1131. ; FLET: Funktionsdefinitionen expandieren,
  1132. ; Body im erweiterten Environment expandieren
  1133. (%put '%expand 'flet
  1134.   (function %expand-flet
  1135.     (lambda (form)
  1136.       (if (null (second form))
  1137.         (values (%expand-form (cons 'PROGN (cddr form))) t)
  1138.         (let ((newfenv (%expand-fundefs-1 (second form))))
  1139.           (multiple-value-call #'%expand-cons form
  1140.             (car form) nil
  1141.             (multiple-value-call #'%expand-cons (cdr form)
  1142.               (%expand-fundefs-2 (second form))
  1143.               (let ((*fenv* (apply #'vector newfenv)))
  1144.                 (%expand-list (cddr form))
  1145.   ) ) ) ) ) ) )
  1146. )
  1147.  
  1148. ; LABELS: Funktionsdefinitionen und Body im erweiterten Environment expandieren
  1149. (%put '%expand 'labels
  1150.   (function %expand-labels
  1151.     (lambda (form)
  1152.       (if (null (second form))
  1153.         (values (%expand-form (cons 'PROGN (cddr form))) t)
  1154.         (let ((newfenv (%expand-fundefs-1 (second form))))
  1155.           (let ((*fenv* (apply #'vector newfenv)))
  1156.             (multiple-value-call #'%expand-cons form
  1157.               (car form) nil
  1158.               (multiple-value-call #'%expand-cons (cdr form)
  1159.                 (%expand-fundefs-2 (second form))
  1160.                 (%expand-list (cddr form))
  1161.   ) ) ) ) ) ) )
  1162. )
  1163.  
  1164. ; MACROLET: Body im erweiterten Environment expandieren
  1165. (%put '%expand 'macrolet
  1166.   (function %expand-macrolet
  1167.     (lambda (form)
  1168.       (do ((L1 (second form) (cdr L1))
  1169.            (L2 nil))
  1170.           ((atom L1)
  1171.            (if L1
  1172.              (error-of-type 'program-error
  1173.                (DEUTSCH "Dotted list im Code von MACROLET, endet mit ~S"
  1174.                 ENGLISH "code after MACROLET contains a dotted list, ending with ~S"
  1175.                 FRANCAIS "Le code de MACROLET contient une paire pointΘe, terminΘe par ~S")
  1176.                L1
  1177.              )
  1178.              (let ((*fenv* (apply #'vector (nreverse (cons *fenv* L2)))))
  1179.                (values (%expand-form (cons 'PROGN (cddr form))) t)
  1180.           )) )
  1181.         (let ((macrodef (car L1)))
  1182.           (if (and (consp macrodef) (symbolp (car macrodef)) (consp (cdr macrodef)))
  1183.             (setq L2
  1184.               (cons (make-macro-expandercons macrodef)
  1185.                     (cons (car macrodef) L2)
  1186.             ) )
  1187.             (error-of-type 'program-error
  1188.               (DEUTSCH "Falsche Syntax in MACROLET: ~S"
  1189.                ENGLISH "illegal syntax in MACROLET: ~S"
  1190.                FRANCAIS "syntaxe illΘgale dans MACROLET : ~S")
  1191.               macrodef
  1192.   ) ) ) ) ) )
  1193. )
  1194.  
  1195. ; SYMBOL-MACROLET: Body im erweiterten Environment expandieren
  1196. (%put '%expand 'symbol-macrolet
  1197.   (function %expand-symbol-macrolet
  1198.     (lambda (form)
  1199.       (do ((L1 (second form) (cdr L1))
  1200.            (L2 nil))
  1201.           ((atom L1)
  1202.            (if L1
  1203.              (error-of-type 'program-error
  1204.                (DEUTSCH "Dotted list im Code von SYMBOL-MACROLET, endet mit ~S"
  1205.                 ENGLISH "code after SYMBOL-MACROLET contains a dotted list, ending with ~S"
  1206.                 FRANCAIS "Le code de SYMBOL-MACROLET contient une paire pointΘe, terminΘe par ~S")
  1207.                L1
  1208.              )
  1209.              (let ((*venv* (apply #'vector (nreverse (cons *venv* L2)))))
  1210.                (values (%expand-form (cons 'LOCALLY (cddr form))) t)
  1211.           )) )
  1212.         (let ((symdef (car L1)))
  1213.           (if (and (consp symdef)
  1214.                    (symbolp (car symdef))
  1215.                    (consp (cdr symdef))
  1216.                    (null (cddr symdef))
  1217.               )
  1218.             (setq L2
  1219.               (cons (make-symbol-macro (cadr symdef)) (cons (car symdef) L2))
  1220.             )
  1221.             (error-of-type 'program-error
  1222.               (DEUTSCH "Falsche Syntax in SYMBOL-MACROLET: ~S"
  1223.                ENGLISH "illegal syntax in SYMBOL-MACROLET: ~S"
  1224.                FRANCAIS "syntaxe illΘgale dans SYMBOL-MACROLET : ~S")
  1225.               symdef
  1226.   ) ) ) ) ) )
  1227. )
  1228.  
  1229. ; %HANDLER-BIND: Handlerliste und Body expandieren
  1230. (%put '%expand '%handler-bind
  1231.   (function %expand-%handler-bind
  1232.     (lambda (form)
  1233.       (multiple-value-call #'%expand-cons form
  1234.         (first form) nil
  1235.         (multiple-value-call #'%expand-cons (rest form)
  1236.           (%expand-handlers (second form))
  1237.           (%expand-list (cddr form))
  1238.   ) ) ) )
  1239. )
  1240.  
  1241. )
  1242.  
  1243. ; Hilfsfunktionen fⁿr die Expansion:
  1244.  
  1245. ; expandiert eine Liste von Formen. 2 Werte.
  1246. (defun %expand-list (l)
  1247.   (if (atom l)
  1248.     (if l
  1249.       (error-of-type 'program-error
  1250.         (DEUTSCH "Dotted list im Code, endet mit ~S"
  1251.          ENGLISH "code contains a dotted list, ending with ~S"
  1252.          FRANCAIS "une paire pointΘe dans le code, terminΘe par ~S")
  1253.         l
  1254.       )
  1255.       (values nil nil)
  1256.     )
  1257.     (multiple-value-call #'%expand-cons l
  1258.                          (%expand-form (first l))
  1259.                          (%expand-list (rest l))
  1260. ) ) )
  1261.  
  1262. ; Fⁿgt lexikalische Variablen zu *venv* hinzu.
  1263. ; (Wird nur dazu benutzt, um Symbol-Macros zu ⁿberdecken.)
  1264. (defun %expand-lexical-variables (vars)
  1265.   (if vars
  1266.     (setq *venv*
  1267.       (apply #'vector
  1268.         (nconc (mapcan #'(lambda (v) (list v nil)) vars) (list *venv*))
  1269. ) ) ) )
  1270.  
  1271. ; Fⁿgt SPECIAL-Deklarationen am Anfang eines Body zu *venv* hinzu.
  1272. (defun %expand-special-declarations (body)
  1273.   (multiple-value-bind (body-rest declarations)
  1274.       (sys::parse-body body nil (vector *venv* *fenv*))
  1275.     (declare (ignore body-rest)) ; Deklarationen nicht wegwerfen!
  1276.     (let ((specials nil))
  1277.       (mapc #'(lambda (declspec)
  1278.                 (if (and (consp declspec) (null (cdr (last declspec))))
  1279.                   (if (eq (car declspec) 'SPECIAL)
  1280.                     (mapc #'(lambda (x) (if (symbolp x) (setq specials (cons x specials))))
  1281.                           (cdr declspec)
  1282.               ) ) ) )
  1283.             (nreverse declarations)
  1284.       )
  1285.       (%expand-lexical-variables (nreverse specials)) ; auf specdecl kommt es hier nicht an
  1286. ) ) )
  1287.  
  1288. ; expandiert einen Funktionsnamen, der ein Cons ist (das mu▀ ein
  1289. ; Lambda-Ausdruck sein). 2 Werte.
  1290. (defun %expand-lambda (l)
  1291.   (unless (eq (first l) 'lambda)
  1292.     (error-of-type 'program-error
  1293.       (DEUTSCH "~S: ~S sollte LAMBDA-Ausdruck sein"
  1294.        ENGLISH "~S: ~S should be a lambda expression"
  1295.        FRANCAIS "~S : ~S devrait Ωtre une expression LAMBDA")
  1296.       '%expand-form l
  1297.   ) )
  1298.   (multiple-value-call #'%expand-cons l
  1299.       'lambda nil ; LAMBDA
  1300.       (%expand-lambdabody (rest l))
  1301. ) )
  1302.  
  1303. ; expandiert den CDR eines Lambda-Ausdrucks, ein (lambdalist . body). 2 Werte.
  1304. (defun %expand-lambdabody (lambdabody)
  1305.   (let ((body (rest lambdabody)))
  1306.     (if (and (consp body)
  1307.              (let ((form (car body)))
  1308.                (and (consp form)
  1309.                     (eq (car form) 'DECLARE)
  1310.                     (let ((declspecs (cdr form)))
  1311.                       (and (consp declspecs)
  1312.                            (let ((declspec (car declspecs)))
  1313.                              (and (consp declspec)
  1314.                                   (eq (car declspec) 'SOURCE)
  1315.         )    ) )    ) )    ) )
  1316.       (values lambdabody nil) ; bereits expandiert -> unberⁿhrt lassen
  1317.       (let ((*venv* *venv*))
  1318.         (values (list*
  1319.                   (%expand-lambdalist (first lambdabody))
  1320.                   (list 'DECLARE (list 'SOURCE lambdabody))
  1321.                   (%expand-list (rest lambdabody))
  1322.                 )
  1323.                 t
  1324. ) ) ) ) )
  1325.  
  1326. ; expandiert eine Lambdaliste. 2 Werte.
  1327. (defun %expand-lambdalist (ll)
  1328.   (if (atom ll)
  1329.     (if ll
  1330.       (error-of-type 'program-error
  1331.         (DEUTSCH "Lambdaliste darf nicht mit dem Atom ~S enden"
  1332.          ENGLISH "lambda list must not end with the atom ~S"
  1333.          FRANCAIS "La liste lambda ne peut pas se terminer par l'atome ~S")
  1334.         ll
  1335.       )
  1336.       (values nil nil)
  1337.     )
  1338.     (multiple-value-call #'%expand-cons ll
  1339.         (%expand-parspez (first ll))
  1340.         (progn
  1341.           (let ((v (first ll)))
  1342.             (if (not (member v lambda-list-keywords :test #'eq))
  1343.               (setq *venv* (vector (%expand-varspec-var v) nil *venv*))
  1344.           ) )
  1345.           (%expand-lambdalist (rest ll))
  1346. ) ) )   )
  1347.  
  1348. ; expandiert ein Element einer Lambdaliste. 2 Werte.
  1349. ; (Expandiert dabei nur bei Listen, und dann auch nur das zweite Element.)
  1350. (defun %expand-parspez (ps)
  1351.   (if (or (atom ps) (atom (rest ps)))
  1352.     (values ps nil)
  1353.     (multiple-value-call #'%expand-cons ps
  1354.         (first ps) nil
  1355.         (multiple-value-call #'%expand-cons (rest ps)
  1356.             (%expand-form (second ps))
  1357.             (cddr ps) nil
  1358. ) ) )   )
  1359.  
  1360. ; expandiert eine Variablenliste fⁿr LET. 2 Werte.
  1361. (defun %expand-varspez (vs &optional (nvenv nil))
  1362.   (if (atom vs)
  1363.     (if vs
  1364.       (error-of-type 'program-error
  1365.         (DEUTSCH "~S: Variablenliste endet mit dem Atom ~S"
  1366.          ENGLISH "~S: variable list ends with the atom ~S"
  1367.          FRANCAIS "~S : La liste de variables se termine par l'atome ~S")
  1368.         'let vs
  1369.       )
  1370.       (progn
  1371.         (setq *venv* (apply #'vector (nreverse (cons *venv* nvenv))))
  1372.         (values nil nil)
  1373.     ) )
  1374.     (multiple-value-call #'%expand-cons vs
  1375.         (%expand-parspez (first vs)) ; Bei Liste 2. Element expandieren
  1376.         (%expand-varspez (rest vs) (list* nil (%expand-varspec-var (first vs)) nvenv))
  1377. ) ) )
  1378.  
  1379. ; expandiert eine Variablenliste fⁿr LET*. 2 Werte.
  1380. (defun %expand-varspez* (vs)
  1381.   (if (atom vs)
  1382.     (if vs
  1383.       (error-of-type 'program-error
  1384.         (DEUTSCH "~S: Variablenliste endet mit dem Atom ~S"
  1385.          ENGLISH "~S: variable list ends with the atom ~S"
  1386.          FRANCAIS "~S : La liste de variables se termine par l'atome ~S")
  1387.         'let* vs
  1388.       )
  1389.       (values nil nil)
  1390.     )
  1391.     (multiple-value-call #'%expand-cons vs
  1392.         (%expand-parspez (first vs)) ; Bei Liste 2. Element expandieren
  1393.         (progn
  1394.           (setq *venv* (vector (%expand-varspec-var (first vs)) nil *venv*))
  1395.           (%expand-varspez* (rest vs))
  1396. ) ) )   )
  1397.  
  1398. (defun %expand-varspec-var (varspec)
  1399.   (if (atom varspec) varspec (first varspec))
  1400. )
  1401.  
  1402. (defun %expand-varspec-val (varspec)
  1403.   (if (atom varspec) nil (eval (second varspec)))
  1404. )
  1405.  
  1406. ; Expandiert eine Cond-Klausel-Liste. 2 Werte.
  1407. (defun %expand-cond (clauses)
  1408.   (if (atom clauses)
  1409.     (values clauses nil)
  1410.     (multiple-value-call #'%expand-cons clauses
  1411.         (%expand-list (first clauses))
  1412.         (%expand-cond (rest clauses))
  1413. ) ) )
  1414.  
  1415. ; Auf den bereits expandierten Body wird folgendes angewandt:
  1416. ; (%return-p name list) stellt fest, ob die Formenliste list irgendwo ein
  1417. ; (RETURN-FROM name ...) enthΣlt.
  1418. (defun %return-p (name body)
  1419.   (block return-p
  1420.     (tagbody 1
  1421.       (if (atom body) (return-from return-p nil))
  1422.       (let ((form (car body)))
  1423.         (if
  1424.           ; stelle fest, ob form ein (RETURN-FROM name ...) enthΣlt:
  1425.           (and (consp form)
  1426.                (or (and (eq (first form) 'return-from) ; (RETURN-FROM name ...)
  1427.                         (eq (second form) name)
  1428.                    )
  1429.                    (and (consp (first form))           ; Lambdaliste
  1430.                         (%return-p name (first form))
  1431.                    )
  1432.                    (and (not ; keine neue Definition desselben Blocks ?
  1433.                           (and (eq (first form) 'block) (eq (second form) name))
  1434.                         )
  1435.                         (%return-p name (rest form)) ; Funktionsaufruf
  1436.           )    )   )
  1437.           (return-from return-p t)
  1438.       ) )
  1439.       (setq body (cdr body))
  1440.       (go 1)
  1441. ) ) )
  1442.  
  1443. (defun %expand-varlist-macrop (l)
  1444.   (and (consp l)
  1445.        (or (and (symbolp (car l)) (symbol-macro-p (venv-assoc (car l) *venv*)))
  1446.            (%expand-varlist-macrop (cdr l))
  1447. ) )    )
  1448.  
  1449. (defun %expand-setqlist-macrop (l)
  1450.   (and (consp l) (consp (cdr l))
  1451.        (or (and (symbolp (car l)) (symbol-macro-p (venv-assoc (car l) *venv*)))
  1452.            (%expand-setqlist-macrop (cddr l))
  1453. ) )    )
  1454.  
  1455. (defun %expand-setqlist (l)
  1456.   (if (or (atom l) (atom (cdr l)))
  1457.     (values l nil)
  1458.     (multiple-value-call #'%expand-cons l
  1459.         (first l) nil
  1460.         (multiple-value-call #'%expand-cons (rest l)
  1461.             (%expand-form (second l))
  1462.             (%expand-setqlist (cddr l))
  1463. ) ) )   )
  1464.  
  1465. ; (%expand-tagbody list) expandiert die Elemente einer Liste und lΣ▀t dabei
  1466. ; entstehende Atome fest (damit keine neuen Tags entstehen, die andere Tags
  1467. ; verdecken k÷nnten). 2 Werte.
  1468. (defun %expand-tagbody (body)
  1469.   (cond ((atom body) (values body nil))
  1470.         ((atom (first body))
  1471.          (multiple-value-call #'%expand-cons body
  1472.              (first body) nil
  1473.              (%expand-tagbody (rest body))
  1474.         ))
  1475.         (t (multiple-value-bind (exp flag) (%expand-form (first body))
  1476.              (if (atom exp)
  1477.                (values (%expand-tagbody (rest body)) t) ; weglassen
  1478.                (multiple-value-call #'%expand-cons body
  1479.                    exp flag
  1480.                    (%expand-tagbody (rest body))
  1481. ) )     )  ) ) )
  1482. ; (%expand-fundefs-1 fundefs) liefert eine Liste (name1 nil ... namek nil *fenv*)
  1483. (defun %expand-fundefs-1 (fundefs)
  1484.   (if (atom fundefs)
  1485.     (if fundefs
  1486.       (error-of-type 'program-error
  1487.         (DEUTSCH "FLET/LABELS: Dotted list im Code, endet mit ~S"
  1488.          ENGLISH "FLET/LABELS: code contains a dotted list, ending with ~S"
  1489.          FRANCAIS "FLET/LABELS : une paire pointΘe dans le code, terminΘe par ~S")
  1490.         fundefs
  1491.       )
  1492.       (list *fenv*)
  1493.     )
  1494.     (let ((fundef (car fundefs)))
  1495.       (if (and (consp fundef) (function-name-p (car fundef)) (consp (cdr fundef)))
  1496.         (list* (car fundef) nil (%expand-fundefs-1 (cdr fundefs)))
  1497.         (error-of-type 'program-error
  1498.           (DEUTSCH "Falsche Syntax in FLET/LABELS: ~S"
  1499.            ENGLISH "illegal syntax in FLET/LABELS: ~S"
  1500.            FRANCAIS "syntaxe incorrecte dans FLET/LABELS : ~S")
  1501.           fundef
  1502. ) ) ) ) )
  1503. ; (%expand-fundefs-2 fundefs) expandiert eine Funktionsdefinitionenliste,
  1504. ; wie in FLET, LABELS. 2 Werte.
  1505. (defun %expand-fundefs-2 (fundefs)
  1506.   (if (atom fundefs)
  1507.     (values fundefs nil)
  1508.     (let ((fundef (car fundefs)))
  1509.       (multiple-value-call #'%expand-cons fundefs
  1510.              (multiple-value-call #'%expand-cons fundef
  1511.                      (car fundef) nil
  1512.                      (%expand-lambdabody (cdr fundef))
  1513.              )
  1514.              (%expand-fundefs-2 (rest fundefs))
  1515. ) ) ) )
  1516. ; (%expand-handlers handlers) expandiert eine Typ/Handler-Liste
  1517. ; wie in %HANDLER-BIND. 2 Werte.
  1518. (defun %expand-handlers (handlers)
  1519.   (if (atom handlers)
  1520.     (values handlers nil)
  1521.     (let ((handler (car handlers)))
  1522.       (multiple-value-call #'%expand-cons handlers
  1523.         (multiple-value-call #'%expand-cons handler
  1524.           (car handler) nil
  1525.           (%expand-list (cdr handler))
  1526.         )
  1527.         (%expand-handlers (cdr handlers))
  1528. ) ) ) )
  1529.  
  1530. #|
  1531. ; expandiert eine Form in einem gegebenen Function-Environment
  1532. ; Kann bei Bedarf von EVAL aufgerufen werden.
  1533. (defun %expand-form-main (form *fenv*)
  1534.   (%expand-form form)
  1535. )
  1536. |#
  1537.  
  1538. ; expandiert (lambdalist . body) in einem gegebenen Function-Environment.
  1539. ; Wird von GET_CLOSURE aufgerufen.
  1540. (defun %expand-lambdabody-main (lambdabody *venv* *fenv*)
  1541.   (%expand-lambdabody lambdabody)
  1542. )
  1543.  
  1544. (VALUES) )
  1545.  
  1546. ;; ab hier ist FUNCTION funktionsfΣhig, soweit kein MACROLET darin vorkommt.
  1547.  
  1548. (PROGN
  1549.  
  1550. (proclaim '(special *load-paths*))
  1551. (setq *load-paths* nil)
  1552. (proclaim '(special *source-file-types*))
  1553. (setq *source-file-types* '(#".lsp"))
  1554. (proclaim '(special *compiled-file-types*))
  1555. (setq *compiled-file-types* '(#".fas"))
  1556.  
  1557. ; vorlΣufig brauchen die Files nicht gesucht zu werden:
  1558. (defun search-file (filename extensions)
  1559.   (mapcan #'(lambda (extension)
  1560.               (let ((filename (merge-pathnames filename extension)))
  1561.                 (if (probe-file filename) (list filename) '())
  1562.             ) )
  1563.           (reverse extensions)
  1564. ) )
  1565.  
  1566. (proclaim '(special *load-verbose*))
  1567. (setq *load-verbose* t)
  1568. (proclaim '(special *load-print*))
  1569. (setq *load-print* nil)
  1570. (proclaim '(special *load-echo*))
  1571. (setq *load-echo* nil)
  1572. (proclaim '(special *load-pathname*))
  1573. (setq *load-pathname* nil)
  1574. (proclaim '(special *load-truename*))
  1575. (setq *load-truename* nil)
  1576. (proclaim '(special *load-input-stream*))
  1577. (setq *load-input-stream* nil)
  1578.  
  1579. ; (LOAD filename [:verbose] [:print] [:if-does-not-exist] [:echo] [:compiling]),
  1580. ; CLTL S. 426
  1581. (fmakunbound 'load)
  1582. (defun load (filename
  1583.              &key (verbose *load-verbose*) (print *load-print*) (if-does-not-exist t)
  1584.                   (echo *load-echo*) (compiling nil))
  1585.   (let ((stream
  1586.           (if (streamp filename)
  1587.             filename
  1588.             (or (open (setq filename (pathname filename))
  1589.                   :direction :input-immutable
  1590.                   :element-type 'string-char
  1591.                   :if-does-not-exist nil
  1592.                 )
  1593.                 ; Datei mit genau diesem Namen nicht vorhanden.
  1594.                 ; Suche unter den Dateien mit demselben Namen und den
  1595.                 ; Extensions "LSP", "FAS" die neueste:
  1596.                 (let ((present-files
  1597.                         (search-file filename
  1598.                           (append *source-file-types* *compiled-file-types*)
  1599.                      )) )
  1600.                   (if (endp present-files)
  1601.                     nil
  1602.                     (open (setq filename (first present-files))
  1603.                           :direction :input-immutable
  1604.                           :element-type 'string-char
  1605.        )) ) )   ) ) )
  1606.     (if stream
  1607.       (let* ((input-stream
  1608.                (if echo
  1609.                  (make-echo-stream stream *standard-output*)
  1610.                  stream
  1611.              ) )
  1612.              (*load-input-stream* input-stream)
  1613.              ; :verbose, :print und :echo wirken nicht rekursiv - dazu
  1614.              ; hat man ja gerade die Special-Variablen *load-verbose* etc.
  1615.              ;(*load-verbose* verbose)
  1616.              ;(*load-print* print)
  1617.              ;(*load-echo* echo)
  1618.              (*load-pathname* (if (pathnamep filename) filename nil))
  1619.              (*load-truename* (if (pathnamep filename) (truename filename) nil))
  1620.              (*package* *package*) ; *PACKAGE* binden
  1621.              (*readtable* *readtable*) ; *READTABLE* binden
  1622.              (end-of-file "EOF")) ; einmaliges Objekt
  1623.         (when verbose
  1624.           (fresh-line)
  1625.           (write-string (DEUTSCH ";; Datei "
  1626.                          ENGLISH ";; Loading file "
  1627.                          FRANCAIS ";; Chargement du fichier ")
  1628.           )
  1629.           (princ filename)
  1630.           (write-string (DEUTSCH " wird geladen..."
  1631.                          ENGLISH " ..."
  1632.                          FRANCAIS " ...")
  1633.         ) )
  1634.         (block nil
  1635.           (unwind-protect
  1636.             (tagbody weiter
  1637.               (when echo (fresh-line))
  1638.               (let ((obj (read input-stream nil end-of-file)))
  1639.                 (when (eql obj end-of-file) (return-from nil))
  1640.                 (setq obj
  1641.                   (multiple-value-list
  1642.                     (cond ((compiled-function-p obj) (funcall obj))
  1643.                           (compiling (funcall (compile-form obj nil nil nil nil nil)))
  1644.                           (t (eval obj))
  1645.                 ) ) )
  1646.                 (when print (when obj (print (first obj))))
  1647.               )
  1648.               (go weiter)
  1649.             )
  1650.             (close stream) (close input-stream)
  1651.         ) )
  1652.         (when verbose
  1653.           (fresh-line)
  1654.           (write-string (DEUTSCH ";; Datei "
  1655.                          ENGLISH ";; Loading of file "
  1656.                          FRANCAIS ";; Le fichier ")
  1657.           )
  1658.           (princ filename)
  1659.           (write-string (DEUTSCH " ist geladen."
  1660.                          ENGLISH " is finished."
  1661.                          FRANCAIS " est chargΘ.")
  1662.         ) )
  1663.         t
  1664.       )
  1665.       (if if-does-not-exist
  1666.         (error-of-type 'file-error
  1667.           :pathname filename
  1668.           (DEUTSCH "Ein Datei mit Namen ~A gibt es nicht."
  1669.            ENGLISH "A file with name ~A does not exist"
  1670.            FRANCAIS "Il n'existe pas de fichier de nom ~A.")
  1671.           filename
  1672.         )
  1673.         nil
  1674.       )
  1675. ) ) )
  1676.  
  1677. ; vorlΣufig:
  1678. (sys::%putd 'defun
  1679.   (cons 'sys::macro
  1680.     (function defun
  1681.       (lambda (form env)
  1682.         (unless (and (consp (cdr form)) (consp (cddr form)))
  1683.           (error-of-type 'program-error
  1684.             (DEUTSCH "~S: Funktionsname und/oder Parameterliste fehlt"
  1685.              ENGLISH "~S: missing function name and/or parameter list"
  1686.              FRANCAIS "~S : Le nom de fonction et/ou la liste de paramΦtre manque")
  1687.             'defun
  1688.         ) )
  1689.         (let ((name (cadr form))
  1690.               (lambdalist (caddr form))
  1691.               (body (cdddr form)))
  1692.           (unless (symbolp name)
  1693.             (error-of-type 'program-error
  1694.               (DEUTSCH "~S: ~S ist kein Symbol."
  1695.                ENGLISH "~S: ~S is not a symbol."
  1696.                FRANCAIS "~S : ~S n'est pas un symbole.")
  1697.               'defun name
  1698.           ) )
  1699.           (when (special-form-p name)
  1700.             (error-of-type 'program-error
  1701.               (DEUTSCH "~S: Spezialform ~S kann nicht umdefiniert werden."
  1702.                ENGLISH "~S: special form ~S cannot be redefined."
  1703.                FRANCAIS "~S : La forme spΘciale ~S ne peut pas Ωtre redΘfinie.")
  1704.               'defun name
  1705.           ) )
  1706.           (multiple-value-bind (body-rest declarations docstring)
  1707.                                (sys::parse-body body t env)
  1708.             (declare (ignore docstring))
  1709.             #|
  1710.             `(PROGN
  1711.                (SYS::%PUT ',name 'SYS::DEFINITION
  1712.                  (CONS ',form (THE-ENVIRONMENT))
  1713.                )
  1714.                (SYS::%PUTD ',name
  1715.                  (FUNCTION ,name
  1716.                    (LAMBDA ,lambdalist
  1717.                      (DECLARE (SYS::IN-DEFUN ,name) ,@declarations)
  1718.                      (BLOCK ,name ,@body-rest)
  1719.                ) ) )
  1720.                ',name
  1721.              )
  1722.             |#
  1723.             (list 'progn
  1724.               (list 'sys::%put (list 'quote name) ''sys::definition
  1725.                     (list 'cons (list 'quote form) '(the-environment))
  1726.               )
  1727.               (list 'sys::%putd (list 'quote name)
  1728.                 (list 'FUNCTION name
  1729.                   (list 'LAMBDA lambdalist
  1730.                         (list* 'DECLARE (list 'SYS::IN-DEFUN name) declarations)
  1731.                         (list* 'BLOCK name body-rest)
  1732.               ) ) )
  1733.               (list 'quote name)
  1734.             )
  1735.     ) ) ) )
  1736. ) )
  1737.  
  1738. ; vorlΣufige Definition des Macros DO :
  1739. (sys::%putd 'do
  1740.   (cons 'sys::macro
  1741.     (function do
  1742.       (lambda (form env)
  1743.         (let ((varclauselist (second form))
  1744.               (exitclause (third form))
  1745.               (body (cdddr form)))
  1746.           (when (atom exitclause)
  1747.             (error-of-type 'program-error
  1748.               (DEUTSCH "Exitclause in ~S mu▀ Liste sein."
  1749.                ENGLISH "exit clause in ~S must be a list"
  1750.                FRANCAIS "La clause de sortie dans ~S doit Ωtre une liste.")
  1751.               'do
  1752.           ) )
  1753.           (let ((bindlist nil)
  1754.                 (reinitlist nil)
  1755.                 (bodytag (gensym))
  1756.                 (exittag (gensym)))
  1757.             (multiple-value-bind (body-rest declarations)
  1758.                                  (sys::parse-body body nil env)
  1759.               (block do
  1760.                 (tagbody 1
  1761.                   (when (atom varclauselist)
  1762.                     (return-from do
  1763.                       #|
  1764.                       `(block nil
  1765.                          (let ,(nreverse bindlist)
  1766.                            (declare ,@declarations)
  1767.                            (tagbody
  1768.                              (go ,exittag)
  1769.                              ,bodytag
  1770.                              ,@body-rest
  1771.                              (psetq ,@(nreverse reinitlist))
  1772.                              ,exittag
  1773.                              (or ,(first exitclause) (go ,bodytag))
  1774.                              (return-from nil (progn ,@(rest exitclause)))
  1775.                        ) ) )
  1776.                       |#
  1777.                       (list 'block 'nil
  1778.                         (list 'let (nreverse bindlist)
  1779.                           (cons 'declare declarations)
  1780.                           (list* 'tagbody
  1781.                             (list 'go exittag)
  1782.                             bodytag
  1783.                             (append body-rest
  1784.                               (list
  1785.                                 (cons 'psetq (nreverse reinitlist))
  1786.                                 exittag
  1787.                                 (list 'or (first exitclause) (list 'go bodytag))
  1788.                                 (list 'return-from 'nil
  1789.                                   (cons 'progn (rest exitclause))
  1790.                       ) ) ) ) ) )
  1791.                   ) )
  1792.                   (let ( (varclause (first varclauselist)) )
  1793.                        (setq varclauselist (rest varclauselist))
  1794.                        (cond ( (atom varclause)
  1795.                                   (setq bindlist
  1796.                                         (cons varclause bindlist)) )
  1797.                              ( (atom (cdr varclause))
  1798.                                   (setq bindlist
  1799.                                         (cons (first varclause) bindlist)) )
  1800.                              ( (atom (cddr varclause))
  1801.                                   (setq bindlist
  1802.                                         (cons varclause bindlist)) )
  1803.                              ( t (setq bindlist
  1804.                                        (cons (list (first varclause)
  1805.                                                    (second varclause))
  1806.                                              bindlist))
  1807.                                  (setq reinitlist
  1808.                                        (list* (third varclause)
  1809.                                               (first varclause)
  1810.                                               reinitlist)) )))
  1811.                   (go 1)
  1812.     ) ) ) ) ) ) )
  1813. ) )
  1814.  
  1815. ; vorlΣufige Definition des Macros DOTIMES :
  1816. (sys::%putd 'dotimes
  1817.   (cons 'sys::macro
  1818.     (function dotimes
  1819.       (lambda (form env)
  1820.         (let ((var (first (second form)))
  1821.               (countform (second (second form)))
  1822.               (resultform (third (second form)))
  1823.               (body (cddr form)))
  1824.           (multiple-value-bind (body-rest declarations)
  1825.                                (sys::parse-body body nil env)
  1826.             (let ((g (gensym)))
  1827.               #|
  1828.               `(DO ((,var 0 (1+ ,var))
  1829.                     (,g ,countform))
  1830.                    ((>= ,var ,g) ,resultform)
  1831.                  (declare ,@declarations)
  1832.                  ,@body-rest
  1833.                )
  1834.               |#
  1835.               (list* 'do (list (list var '0 (list '1+ var)) (list g countform))
  1836.                          (list (list '>= var g) resultform)
  1837.                      (cons 'declare declarations)
  1838.                      body-rest
  1839.               )
  1840.     ) ) ) ) )
  1841. ) )
  1842.  
  1843. (VALUES) )
  1844.  
  1845. ;; ab hier sind LOAD, DEFUN, DO, DOTIMES (eingeschrΣnkt) funktionsfΣhig.
  1846.  
  1847. (LOAD "defseq")   ;; Definitionen von Standard-Sequences
  1848.  
  1849. (LOAD "backquot") ;; Backquote-Readmacro
  1850.  
  1851. (PROGN
  1852.  
  1853. (sys::%putd 'sys::backquote
  1854.   (cons 'sys::macro
  1855.     (function sys::backquote
  1856.       (lambda (form &optional env) (declare (ignore env)) (third form))
  1857. ) ) )
  1858.  
  1859. (VALUES) )
  1860.  
  1861. ;; ab hier ist Backquote funktionsfΣhig
  1862.  
  1863. (LOAD "defmacro")
  1864.  
  1865. ;; ab hier ist FUNCTION (uneingeschrΣnkt) funktionsfΣhig.
  1866.  
  1867. (PROGN
  1868.  
  1869. (sys::%putd 'defmacro
  1870.   (cons 'sys::macro
  1871.     (function defmacro
  1872.       (lambda (form &optional env)
  1873.         (declare (ignore env))
  1874.         (multiple-value-bind (expansion name lambdalist docstring)
  1875.                              (sys::make-macro-expansion (cdr form))
  1876.           (declare (ignore lambdalist))
  1877.           `(LET ()
  1878.              (EVAL-WHEN (COMPILE LOAD EVAL)
  1879.                (SYSTEM::REMOVE-OLD-DEFINITIONS ',name)
  1880.                ,@(if docstring
  1881.                    `((SYSTEM::%SET-DOCUMENTATION ',name 'FUNCTION ',docstring))
  1882.                    '()
  1883.                  )
  1884.                (SYSTEM::%PUTD ',name (CONS 'SYSTEM::MACRO ,expansion))
  1885.              )
  1886.              (EVAL-WHEN (EVAL)
  1887.                (SYSTEM::%PUT ',name 'SYSTEM::DEFINITION
  1888.                  (CONS ',form (THE-ENVIRONMENT))
  1889.              ) )
  1890.              ',name
  1891.            )
  1892.     ) ) )
  1893. ) )
  1894.  
  1895. (sys::%putd 'defun
  1896.   (cons 'sys::macro
  1897.     (function defun
  1898.       (lambda (form env)
  1899.         (if (atom (cdr form))
  1900.           (error-of-type 'program-error
  1901.             (DEUTSCH "~S: Daraus kann keine Funktion definiert werden: ~S"
  1902.              ENGLISH "~S: cannot define a function from that: ~S"
  1903.              FRANCAIS "~S : Pas de dΘfinition de fonction possible α partir de: ~S")
  1904.             'defun (cdr form)
  1905.         ) )
  1906.         (unless (function-name-p (cadr form))
  1907.           (error-of-type 'program-error
  1908.             (DEUTSCH "~S: Der Name einer Funktion mu▀ ein Symbol sein, nicht: ~S"
  1909.              ENGLISH "~S: the name of a function must be a symbol, not ~S"
  1910.              FRANCAIS "~S : Le nom d'une fonction doit Ωtre un symbole et non ~S")
  1911.             'defun (cadr form)
  1912.         ) )
  1913.         (if (atom (cddr form))
  1914.           (error-of-type 'program-error
  1915.             (DEUTSCH "~S: Die Funktion ~S hat keine Lambdaliste."
  1916.              ENGLISH "~S: function ~S is missing a lambda list"
  1917.              FRANCAIS "~S : Il manque une liste lambda α la fonction ~S.")
  1918.             'defun (cadr form)
  1919.         ) )
  1920.         (let ((name (cadr form))
  1921.               (lambdalist (caddr form))
  1922.               (body (cdddr form)))
  1923.           (multiple-value-bind (body-rest declarations docstring)
  1924.                                (sys::parse-body body t env)
  1925.             (let ((symbolform
  1926.                     (if (atom name)
  1927.                       `',name
  1928.                       `(LOAD-TIME-VALUE (GET-SETF-SYMBOL ',(second name)))
  1929.                   ) )
  1930.                   (lambdabody
  1931.                     `(,lambdalist (DECLARE (SYS::IN-DEFUN ,name) ,@declarations)
  1932.                        (BLOCK ,(block-name name) ,@body-rest)
  1933.                      )
  1934.                  ))
  1935.               `(LET ()
  1936.                  (SYSTEM::REMOVE-OLD-DEFINITIONS ,symbolform)
  1937.                  ,@(if (and compiler::*compiling*
  1938.                             compiler::*compiling-from-file*
  1939.                             (member name compiler::*inline-functions* :test #'eq)
  1940.                             (null compiler::*venv*)
  1941.                             (null compiler::*fenv*)
  1942.                             (null compiler::*benv*)
  1943.                             (null compiler::*genv*)
  1944.                             (eql compiler::*denv* *toplevel-denv*)
  1945.                        )
  1946.                      ; Lambdabody fⁿr Inline-Compilation aufheben:
  1947.                      `((EVAL-WHEN (COMPILE)
  1948.                          (COMPILER::C-DEFUN ',name ',lambdabody)
  1949.                        )
  1950.                        (EVAL-WHEN (LOAD)
  1951.                          (SYSTEM::%PUT ,symbolform 'SYSTEM::INLINE-EXPANSION ',lambdabody)
  1952.                       ))
  1953.                      `((EVAL-WHEN (COMPILE) (COMPILER::C-DEFUN ',name)))
  1954.                    )
  1955.                  ,@(if docstring
  1956.                      `((SYSTEM::%SET-DOCUMENTATION ,symbolform 'FUNCTION ',docstring))
  1957.                      '()
  1958.                    )
  1959.                  (SYSTEM::%PUTD ,symbolform
  1960.                    (FUNCTION ,name (LAMBDA ,@lambdabody))
  1961.                  )
  1962.                  (EVAL-WHEN (EVAL)
  1963.                    (SYSTEM::%PUT ,symbolform 'SYSTEM::DEFINITION
  1964.                      (CONS ',form (THE-ENVIRONMENT))
  1965.                  ) )
  1966.                  ',name
  1967.                )
  1968.     ) ) ) ) )
  1969. ) )
  1970.  
  1971. (VALUES) )
  1972.  
  1973. ;; ab hier sind DEFMACRO und DEFUN funktionsfΣhig.
  1974.  
  1975. ; (MACRO-EXPANDER . macrodef)                                         [Macro]
  1976. ; expandiert zum Macro-Expander als Programmtext (FUNCTION ... (LAMBDA ...)).
  1977. (defmacro MACRO-EXPANDER (&body macrodef)
  1978.   (make-macro-expansion macrodef)
  1979. )
  1980.  
  1981. (LOAD "macros1")  ;; Kontrollstrukturen - Macros
  1982. (LOAD "macros2")  ;; weitere Macros
  1983.  
  1984. (LOAD "defs1")    ;; Definitionen zu Symbolen, Zahlen, Characters, Zeit
  1985. #-UNIX (LOAD "timezone") ;; Definition der Zeitzone
  1986.  
  1987. (LOAD "places")   ;; SETF-Places: Definitionen und Macros
  1988.  
  1989. ;; ab hier ist SETF u.Σ. funktionsfΣhig.
  1990.  
  1991. (LOAD "floatpri") ;; Ausgabe von Floating-Points
  1992.  
  1993. (LOAD "type")     ;; TYPEP
  1994.  
  1995. (LOAD "defstruc") ;; DEFSTRUCT-Macro
  1996.  
  1997. (LOAD "format")   ;; FORMAT
  1998.  
  1999. ; Ein Stⁿckchen "DO-WHAT-I-MEAN":
  2000. ; Sucht ein Programm-File.
  2001. ; Gesucht wird im aktuellen Directory und dann in den Directories
  2002. ; aus *load-paths*.
  2003. ; Ist eine Extension angegeben, so wird nur nach Files mit genau dieser
  2004. ; Extension gesucht. Ist keine Extension angegeben, so wird nur nach Files
  2005. ; mit einer Extension aus der gegebenen Liste gesucht.
  2006. ; Man erhΣlt alle Files aus dem ersten passenden Directory, als Pathnames,
  2007. ; in einer Liste, nach fallendem FILE-WRITE-DATE sortiert, oder NIL.
  2008. (defun search-file (filename extensions
  2009.                     &aux (use-extensions (null (pathname-type filename))) )
  2010.   (when use-extensions
  2011.     (setq extensions ; Case-Konversionen auf den Extensions durchfⁿhren
  2012.       (mapcar #'pathname-type extensions)
  2013.   ) )
  2014.   ; Defaults einmergen:
  2015.   (setq filename (merge-pathnames filename '#".*"))
  2016.   ; Suchen:
  2017.   (let ((already-searched nil))
  2018.     (dolist (dir (cons '#""
  2019.                        ; Wenn filename ".." enthΣlt, zΣhlt *load-paths* nicht
  2020.                        ; (um Errors wegen ".../../foo" z.B. auf DOS zu vermeiden):
  2021.                        (if (member #+(or DOS AMIGA ACORN-RISCOS) :PARENT
  2022.                                    #+(or UNIX OS/2) ".."
  2023.                                    (pathname-directory filename)
  2024.                                    :test #'equal
  2025.                            )
  2026.                          '()
  2027.                          (mapcar #'pathname *load-paths*)
  2028.             )    )     )
  2029.       (let ((search-filename
  2030.               (merge-pathnames (merge-pathnames filename dir))
  2031.            ))
  2032.         (unless (member search-filename already-searched :test #'equal)
  2033.           (let ((xpathnames (directory search-filename :full t :circle t)))
  2034.             (when use-extensions
  2035.               ; nach passenden Extensions filtern:
  2036.               (setq xpathnames
  2037.                 (delete-if-not ; hat xpathname eine der gegebenen Extensions?
  2038.                   #'(lambda (xpathname)
  2039.                       (member (pathname-type (first xpathname)) extensions
  2040.                               :test #-(or AMIGA OS/2) #'string=
  2041.                                     #+(or AMIGA OS/2) #'string-equal
  2042.                     ) )
  2043.                   xpathnames
  2044.             ) ) )
  2045.             (when xpathnames
  2046.               ; nach Datum sortiert, zurⁿckgeben:
  2047.               (dolist (xpathname xpathnames)
  2048.                 (setf (rest xpathname)
  2049.                       (apply #'encode-universal-time (third xpathname))
  2050.               ) )
  2051.               (return (mapcar #'first (sort xpathnames #'> :key #'rest)))
  2052.           ) )
  2053.           (push search-filename already-searched)
  2054.     ) ) )
  2055. ) )
  2056.  
  2057. (LOAD "user1")    ;; User-Interface, Teil 1: Break-Loop, Stepper
  2058.  
  2059. (LOAD "user2")    ;; User-Interface, Teil 2: Apropos, Describe, Dribble, Ed
  2060.  
  2061. (LOAD "trace")    ;; User-Interface, Teil 3: TRACE
  2062.  
  2063. ;(LOAD "macros3")  ;; weitere Macros, optional
  2064.  
  2065. (LOAD "config")   ;; Konfigurations-Parameter
  2066.  
  2067. (LOAD "compiler") ;; Compiler
  2068.  
  2069. (LOAD "disassem") ;; Disassembler
  2070.  
  2071. (LOAD "defs2")    ;; CLtL2-Definitionen, optional
  2072.  
  2073. (LOAD "loop")     ;; CLtL2/dpANS-LOOP, optional
  2074.  
  2075. (LOAD "clos")     ;; CLOS, optional
  2076.  
  2077. (LOAD "conditio") ;; Conditions, optional
  2078.  
  2079. (LOAD "defs3")    ;; CLtL2-Definitionen, optional
  2080.  
  2081. (LOAD "gstream")  ;; generic streams, optional
  2082.  
  2083. #+FFI ; when (find-package "FFI")
  2084. (LOAD "foreign1") ;; foreign function interface, optional
  2085.  
  2086. (when (or #+AMIGA t (find-package "SCREEN"))
  2087.   (LOAD "screen") ;; Screen-Paket, optional
  2088. )
  2089.  
  2090. (when (find-package "STDWIN")
  2091.   (LOAD "stdwin2") ;; STDWIN-Schnittstelle, optional
  2092. )
  2093.  
  2094. #+AMIGA (LOAD "rexx1") ;; Rexx-Schnittstelle, optional
  2095.  
  2096. (in-package "USER") ;; Default-Package aktuell machen
  2097.  
  2098.